官网: echarts官网

先安装

npm install echarts --save

 到main.js引入

import echarts from 'echarts'

Vue.prototype.echarts = echarts

 然后就能使用了

<div id="myEcharts" :style="{width: '400px', height: '400px',fontSize:'25px'}"></div>


mounted() {
      this.drawing()
    },
    methods:{
      drawing(){
        this.echarts.init(document.getElementById('myEcharts')).setOption({
          series: {
            type: 'pie',
            data: [
              {name: '故障', value: 1},
              {name: '正常', value: 2},
            ],
            center: ['50%', '50%'],
            grid:{left:'3%',right:'3%',bottom:'10%', containLabel:true},
            itemStyle:{normal:{label:{
              show: true, formatter: '{b}',textStyle:{fontSize : 16}
                },color:function (params) {
                  var colorList = [
                    'red','#0bd687'
                  ];
                  return colorList[params.dataIndex]
                }
            }}
          }
        });
      }
    }

 

Logo

前往低代码交流专区

更多推荐