|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +import { defineComponent, PropType, ref } from 'vue' |
| 19 | +import initChart from '@/components/chart' |
| 20 | +import type { Ref } from 'vue' |
| 21 | + |
| 22 | +const props = { |
| 23 | + height: { |
| 24 | + type: [String, Number] as PropType<string | number>, |
| 25 | + default: 400, |
| 26 | + }, |
| 27 | + width: { |
| 28 | + type: [String, Number] as PropType<string | number>, |
| 29 | + default: '100%', |
| 30 | + }, |
| 31 | +} |
| 32 | + |
| 33 | +const BarChart = defineComponent({ |
| 34 | + name: 'BarChart', |
| 35 | + props, |
| 36 | + setup() { |
| 37 | + const barChartRef: Ref<HTMLDivElement | null> = ref(null) |
| 38 | + |
| 39 | + const option = { |
| 40 | + tooltip: { |
| 41 | + trigger: 'axis', |
| 42 | + axisPointer: { |
| 43 | + type: 'shadow', |
| 44 | + }, |
| 45 | + backgroundColor: '#fff', |
| 46 | + }, |
| 47 | + grid: { |
| 48 | + left: '3%', |
| 49 | + right: '4%', |
| 50 | + bottom: '3%', |
| 51 | + containLabel: true, |
| 52 | + }, |
| 53 | + xAxis: [ |
| 54 | + { |
| 55 | + type: 'category', |
| 56 | + data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], |
| 57 | + axisTick: { |
| 58 | + alignWithLabel: true, |
| 59 | + }, |
| 60 | + }, |
| 61 | + ], |
| 62 | + yAxis: [ |
| 63 | + { |
| 64 | + type: 'value', |
| 65 | + }, |
| 66 | + ], |
| 67 | + series: [ |
| 68 | + { |
| 69 | + name: 'Direct', |
| 70 | + type: 'bar', |
| 71 | + barWidth: '60%', |
| 72 | + data: [10, 52, 200, 334, 390, 330, 220], |
| 73 | + }, |
| 74 | + ], |
| 75 | + } |
| 76 | + |
| 77 | + initChart(barChartRef, option) |
| 78 | + |
| 79 | + return { barChartRef } |
| 80 | + }, |
| 81 | + render() { |
| 82 | + const { height, width } = this |
| 83 | + return ( |
| 84 | + <div |
| 85 | + ref='barChartRef' |
| 86 | + style={{ |
| 87 | + height: typeof height === 'number' ? height + 'px' : height, |
| 88 | + width: typeof width === 'number' ? width + 'px' : width, |
| 89 | + }} |
| 90 | + /> |
| 91 | + ) |
| 92 | + }, |
| 93 | +}) |
| 94 | + |
| 95 | +export default BarChart |
0 commit comments