123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <template>
- <div :class="className" :style="{height:height,width:width}" />
- </template>
- <script>
- import echarts from 'echarts'
- require('echarts/theme/macarons') // echarts theme
- import resize from '../mixins/resize'
- export default {
- mixins: [resize],
- props: {
- className: {
- type: String,
- default: 'chart'
- },
- width: {
- type: String,
- default: '100%'
- },
- height: {
- type: String,
- default: '200px'
- },
- chartData: {
- type: Array,
- required: true
- }
- },
- watch: {
- chartData: {
- deep: true,
- handler(val) {
- this.setOptions(val)
- }
- }
- },
- data() {
- return {
- chart: null
- }
- },
- mounted() {
- this.$nextTick(() => {
- this.initChart()
- })
- },
- beforeDestroy() {
- if (!this.chart) {
- return
- }
- this.chart.dispose()
- this.chart = null
- },
- methods: {
- initChart() {
- this.chart = echarts.init(this.$el, 'macarons');
- this.chart = echarts.init(this.$el, 'macarons')
- this.setOptions(this.chartData)
- },
- setOptions(data) {
- this.chart.setOption({
- graphic:{
- type: 'text',
- left: 'center',
- top: 'center',
- style:{
- text:'本周与上周\n核酸人数',
- textAlign:"center",
- fill:"#333",
- fontSize:14,
- },
- },
- tooltip: {
- trigger: 'item',
- },
- color:['#18A6E2', '#02DB80'],
- legend: {
- show:false,
- // bottom: 10,
- // left: 'center',
- },
- series: [
- {
- name: '',
- type: 'pie',
- radius: ['40%', '70%'],
- avoidLabelOverlap: false,
- center: ['50%', '50%'],
- itemStyle: {
- borderRadius: 10,
- borderColor: '#fff',
- borderWidth: 2
- },
- label: {
- show: false,
- position: 'center'
- },
- // emphasis: {
- // label: {
- // show: true,
- // fontSize: '18',
- // fontWeight: '400',
- // color:"#333"
- // }
- // },
- labelLine: {
- show: false
- },
- // data:data,
- data: [
- { value: 6, name: '上周核酸人数' },
- { value: 4, name: '本周核酸人数' }
- ]
- }
- ]
- })
- }
- }
- }
- </script>
|