¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <basic-container> |
| | | <v-chart id="chart" :auto-resize="true" :options="chartOptions"></v-chart> |
| | | </basic-container> |
| | | </template> |
| | | |
| | | <script> |
| | | import 'echarts' |
| | | import 'echarts/lib/chart/line' |
| | | import 'echarts/lib/chart/pie' |
| | | import 'echarts/lib/chart/bar' |
| | | import 'echarts/lib/component/tooltip' |
| | | import 'echarts/lib/component/title' |
| | | import 'echarts/lib/component/legend' |
| | | |
| | | export default { |
| | | name: "mixCart", |
| | | props: { |
| | | mixData: { |
| | | type: Array, |
| | | default: [] |
| | | }, |
| | | chartName: { |
| | | type: String, |
| | | default: "" |
| | | } |
| | | }, |
| | | data() { |
| | | return { |
| | | chartOptions: { |
| | | title: { |
| | | text: "", |
| | | }, |
| | | grid: { |
| | | left: "3%", |
| | | right: "4%", |
| | | bottom: "3%", |
| | | containLabel: true, |
| | | }, |
| | | tooltip: { |
| | | trigger: "axis", |
| | | axisPointer: { |
| | | type: "shadow", |
| | | }, |
| | | }, |
| | | legend: { |
| | | data: ["æ»é", "æ°å¢"], |
| | | left: "center", |
| | | textStyle: { |
| | | fontSize: 14 // è°æ´åä½å¤§å° |
| | | } |
| | | }, |
| | | xAxis: { |
| | | type: "category", |
| | | data: [ |
| | | "䏿", |
| | | "äºæ", |
| | | "䏿", |
| | | "åæ", |
| | | "äºæ", |
| | | "å
æ", |
| | | "䏿", |
| | | "å
«æ", |
| | | "乿", |
| | | "åæ", |
| | | "å䏿", |
| | | "åäºæ", |
| | | ], |
| | | }, |
| | | yAxis: { |
| | | type: "value", |
| | | }, |
| | | series: [], |
| | | }, |
| | | }; |
| | | }, |
| | | watch: { |
| | | mixData: { |
| | | immediate: true, |
| | | handler(newval, oldval) { |
| | | if (newval) { |
| | | const colors = ["#8fef5b", "#db3c3c"]; |
| | | |
| | | const seriesData = newval.map((data, index) => ({ |
| | | name: index === 0 ? "æ»é" : "æ°å¢", |
| | | type: index === 0 ? "bar" : "line", |
| | | stack: index === 0 ? "æ»é" : null, |
| | | data: data.map(value => ({value})), |
| | | barWidth: 68, |
| | | label: { |
| | | show: true, |
| | | position: "top" |
| | | }, |
| | | itemStyle: { |
| | | color: colors[index] |
| | | }, |
| | | emphasis: { |
| | | focus: "series" |
| | | } |
| | | })); |
| | | |
| | | this.chartOptions.series = seriesData; |
| | | } |
| | | }, |
| | | }, |
| | | chartName:{ |
| | | handler(newval,oldval){ |
| | | if(newval){ |
| | | this.chartOptions.title.text = newval + "æ°æ®ç»è®¡" |
| | | } |
| | | }, |
| | | immediate:true, |
| | | deep:true |
| | | } |
| | | }, |
| | | }; |
| | | </script> |
| | | |
| | | <style scoped lang="scss"> |
| | | #chart { |
| | | width: 100%; |
| | | height: 560px; |
| | | } |
| | | </style> |