| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <template>
- <div :class="className" style="height: 160px;width:160px" />
- </template>
- <script>
- import * as echarts from 'echarts';
- export default {
- name: 'echartsPie',
- props: {
- className: {
- type: String,
- default: 'chart'
- }
- },
- 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.setOption({
- tooltip:{
- show:false,
- },
- hoverAnimation: false,
- title: {
- text: '',
- subtext: '',
- x: 'center',
- y: 'center',
- top: '36%',
- textStyle: {
- fontSize: 12,
- },
- subtextStyle: {
- fontSize: 12,
- color: '#333',
- fontWeight: 700
- }
- },
- animation: false,
- series: [
- {
- type: 'pie',
- center: [45,45],
- radius: ['48%', '55%'],
- label: {
- position: 'center',
- show: true,
- color: '#1E7CE8',
- formatter: ['{a|60}%','{b|实际用水量}'].join('\n'),
- rich: {
- a: {
- fontSize:'22px',
- },
- b:{
- color: '#333333',
- fontSize: '12px',
- padding:[10,0,0,0]
- }
- },
- textStyle: {
- align: "center",
- color: '#333',
- fontSize: 12,
- baseline: "middle"
- },
- lineHeight: 16,
- fontSize: 12,
- },
- itemStyle: {
- color: '#c23531',
- shadowBlur: 200,
- shadowColor: 'rgba(0, 0, 0, 0)'
- },
- emphasis: {
- scale: false,
- selectorLabel:{
- show: false
- },
- itemStyle: {
- color: 'inherit'
- },
- textStyle: {
- fontSize: '30',
- fontWeight: 'bold'
- },
- label: {
- show: false,
- fontWeight: 'bold'
- },
- disable:false, //是否关闭扇区高亮效果
- scale:false, //扇区是否缩放
- scaleSize:0,
- },
- labelLine: {
- show: false
- },
- data: [
- { value: 1048, name: 'Direct',itemStyle:{color: '#1890FF'} },
- { value: 1048, name: 'Direct2',itemStyle:{color: '#D9D9D9'} }
- ]
- }
- ]
- })
- this.chart.on('mouseover',e=>{
- let op = this.chart.getOption()
- this.chart.dispatchAction({
- type: 'downplay',
- animation: false,
- seriesIndex: 0,
- dataIndex: e.dataIndex,
- color: e.color
- })
- this.chart.setOption(op, true)
- })
- }
- }
- }
- </script>
|