<template> <div class="chart-container"> <div ref="chart" class="chart-body" /> </div> </template> <script> import echarts from 'echarts' export default { name: 'SourceStatisChart4Sup', props: { list: { type: Array, default() { return [] } } }, computed: { pieData() { const tmp = [] this.list.forEach(item => { const obj = {} obj.name = item.caseSource obj.value = item.caseNum tmp.push(obj) }) return tmp } }, watch: { list() { this.initChart() } }, activated() { this.initChart() }, methods: { initChart() { this.chart = echarts.init(this.$refs.chart) this.chart.setOption({ grid: { bottom: 120 }, legend: { type: 'scroll', bottom: 0, textStyle: { color: '#f0f0f0' }, pageTextStyle: { color: '#f0f0f0' }, pageIconColor: '#FEFEFE' }, tooltip: { show: true }, toolbox: { show: true, right: '20', feature: { dataView: { show: false } } }, color: [ '#19d4ae', '#5ab1ef', '#fa6e86', '#ffb980', '#0067a6', '#c4b4e4', '#d87a80', '#9cbbff', '#d9d0c7', '#87a997', '#d49ea2', '#5b4947', '#7ba3a8' ], series: [{ name: '问题来源', type: 'pie', data: this.pieData, label: { show: false }, tooltip: { formatter: '{b}<br/>上报数: {c} ({d}%)' } }] }) } } } </script> <style scoped> .chart-container{ /*text-align: center;*/ } .chart-body{ min-height: 240px; width: 90%; margin-right: auto; margin-left: auto; } </style>