echarts在Vue中的使用

下载echarts

npm i echarts --save

引用echarts

import * as echarts from ‘echarts’
注意:不要使用 import echarts from ‘echarts’,后续会报init没有定义的错误

代码

<div class="echart-pie">
    <div ref="echartsOne" class="echartss"></div>
 </div>

data里的代码

  option: {   
  		    tooltip:{},
  	    	legend: {
  	    		data:['数量'],
  	    		//改变字体颜色
                textStyle:{
                   fontSize: 14,//字体大小
                    color: '#ffffff'//字体颜色
                },
  	    	},
  	    	xAxis: {
  	    		data: ['成都','上海','北京','深圳','福建','江苏'],
  	    		//改变x轴颜色
                   axisLabel: {
                        show: true,
                         textStyle: {
                         color: '#fff'
                         }
                  }
  	    	},
  	    	yAxis: {
  	    		//改变y轴颜色
                  axisLabel: {
                      show: true,
                      textStyle: {
                      color: '#fff'
                      }
                 }
              },
  	    	series: [{
  	    		name: '数量',
  	    		type: 'bar',
  	    		data: [12,5,3,0,0,5],
                itemStyle: {
                   normal: {  
                      color: function(params) {
                      //柱状图每一根柱子的颜色
                      var colorList = ['#61a0a8','#91cc75', '#d48265', '#91c7ae','#749f83', '#ca8622'];
                      return colorList[params.dataIndex]
                }
            }
        }
  	 }]        
  }

方法的代码

  mounted() {
      this.setTest()
  },
  methods: {
      setTest(){
          let bar_dv = this.$refs.echartsOne
          if(bar_dv) {
              let myChart = echarts.init(bar_dv);
                myChart.setOption(this.option)
            }
      }
  }

css

//注意一定要给echartss设置宽高,不然就会看不到,因为高度为0
 .echart-pie {  
    width: 100%;
    height: 340px;
    .echartss {
      width: 100%;
      height: 100%;
    }
  }

效果图

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值