| | |
| | | <template> |
| | | <basic-container> |
| | | <basic-container style="width: 100%"> |
| | | <v-chart :options="chartOptions" :auto-resize="true" id="chart"></v-chart> |
| | | </basic-container> |
| | | </template> |
| | |
| | | import 'echarts/lib/component/legend' |
| | | export default { |
| | | name: "pieChart", |
| | | props:{ |
| | | pieData:{ |
| | | type:Array, |
| | | default:[] |
| | | }, |
| | | chartName:{ |
| | | type:String, |
| | | default: "" |
| | | } |
| | | }, |
| | | watch:{ |
| | | pieData:{ |
| | | immediate:true, |
| | | handler(newval,oldval){ |
| | | if (newval) { |
| | | // console.log(newval) |
| | | const series=[ |
| | | { |
| | | name: '', |
| | | type: 'pie', |
| | | radius: ['40%', '70%'], |
| | | avoidLabelOverlap:false, |
| | | label: { |
| | | formatter: '{b}\n{d}%', |
| | | fontSize:14 |
| | | }, |
| | | itemStyle: { |
| | | color: function(params) { |
| | | // 根据具体需求设置颜色 |
| | | const colorList = ['#5470C6', '#91CC75', '#fac858', '#EE6666', '#3BA272', '#FC8452', '#9A60B4', '#e34d4d', '#b3e9b9', '#eaaaed', '#1bc6e4', '#c6b3e9']; |
| | | return colorList[params.dataIndex % colorList.length]; |
| | | } |
| | | }, |
| | | data:newval[0].map((value, index) => { |
| | | return { |
| | | value: value, |
| | | name: this.getMonthName(index), |
| | | newValue: newval[1][index] |
| | | }; |
| | | }), |
| | | } |
| | | ] |
| | | this.chartOptions.series = series; |
| | | } |
| | | } |
| | | }, |
| | | chartName:{ |
| | | handler(newval,oldval){ |
| | | if(newval){ |
| | | this.chartOptions.title.text = newval + "数据统计" |
| | | } |
| | | }, |
| | | immediate:true, |
| | | deep:true |
| | | } |
| | | }, |
| | | data() { |
| | | return { |
| | | chartOptions: { |
| | |
| | | tooltip: { |
| | | trigger: 'item', |
| | | formatter: function (params) { |
| | | var result = ''; |
| | | let result = ''; |
| | | if (params.componentType === 'series') { |
| | | result += params.name + '<br/>'; |
| | | result += '新增:' + params.data.newValue + '<br/>'; |
| | |
| | | top: 'middle', |
| | | data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'] |
| | | }, |
| | | series: [ |
| | | { |
| | | name: '', |
| | | type: 'pie', |
| | | radius: ['40%', '70%'], |
| | | avoidLabelOverlap:false, |
| | | label: { |
| | | formatter: '{b}\n{d}%', |
| | | fontSize:14 |
| | | }, |
| | | itemStyle: { |
| | | color: function(params) { |
| | | // 根据具体需求设置颜色 |
| | | var colorList = ['#5470C6', '#91CC75', '#fac858', '#EE6666', '#3BA272', '#FC8452', '#9A60B4', '#e34d4d', '#b3e9b9', '#eaaaed', '#1bc6e4', '#c6b3e9']; |
| | | return colorList[params.dataIndex % colorList.length]; |
| | | } |
| | | }, |
| | | data: [ |
| | | { value: 110, name: '一月', newValue: 10, totalValue: 110 }, |
| | | { value: 220, name: '二月', newValue: 20, totalValue: 220 }, |
| | | { value: 330, name: '三月', newValue: 30, totalValue: 330 }, |
| | | { value: 440, name: '四月', newValue: 40, totalValue: 440 }, |
| | | { value: 550, name: '五月', newValue: 50, totalValue: 550 }, |
| | | { value: 660, name: '六月', newValue: 60, totalValue: 660 }, |
| | | { value: 770, name: '七月', newValue: 70, totalValue: 770 }, |
| | | { value: 880, name: '八月', newValue: 80, totalValue: 880 }, |
| | | { value: 990, name: '九月', newValue: 90, totalValue: 990 }, |
| | | { value: 1100, name: '十月', newValue: 100, totalValue: 1100 }, |
| | | { value: 1210, name: '十一月', newValue: 110, totalValue: 1210 }, |
| | | { value: 1320, name: '十二月', newValue: 120, totalValue: 1320 } |
| | | ] |
| | | } |
| | | ] |
| | | series: [] |
| | | }, |
| | | } |
| | | }, |
| | | methods:{ |
| | | getMonthName(index){ |
| | | const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']; |
| | | return monthNames[index]; |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | <style scoped lang="scss"> |
| | | #chart { |
| | | width: 800px; |
| | | height: 600px; |
| | | width: 90%; |
| | | height: 530px; |
| | | } |
| | | |
| | | </style> |