echarts使用总结

echarts的基本使用

1.grid:调整的是图片的位置

grid:{
	top:0;
	right:0
	bottom:0;
	left:0
}

grid可以填具体的数值,也可以是百分比(占盛放容器大小的百分比),left代表的是与容器左侧的空隙,right代表与容器右侧的空隙,top和bottom分别代表与上下的空隙。
在这里插入图片描述

2. legend:图例

legend: {
        icon:"circle", //图标形状
        itemHeight:18, //图标高度
        itemGap:24,//图例之间的间距
        orient:'vertical', //图例的排列方式
        left:'50%', //图例的位置(左)
        y:'center', //图例在垂直方向上的位置,也可以使用top,bottom替代
        textStyle:{
          fontSize:18,  //图例文字大小
          color:'#999999' //图例文字颜色
        },
        formatter:function(name){   //修改图例展示内容
          let data=option.series[0].data;
          let sum=0;
          for(let i=0;i<data.length;i++){
            sum+=data[i].value
          }
          let tarValue;
          let tarPer;
          for(let i=0;i<data.length;i++){
            if(data[i].name===name){
              tarValue=data[i].value
              tarPer=((data[i].value/sum)*100).toFixed(2)

            }
          }
          return name+"    "+tarPer+"%" +"    "+tarValue;
        }
      },

3.xAxis,yAxis:坐标轴

xAxis: {
      show:true, //是否展示坐标轴
      type: 'category',
      axisLine:{
        show:true,//是否展示坐标轴线
        lineStyle:{
          color:'#F3F6FA '//坐标轴线颜色
        }
      },
      axisLabel:{
        color:'#67808E'//坐标轴文字颜色
      }
    },

4.图表自适应

var elementResizeDetectorMaker = require("element-resize-detector");
mounted() {
      this.energyWater()
      this.drawMoneyPie()
      this.drawMoneyCategory()
      this.drawCircle()
      this.drawCircle2()
      this.chartResize()
      window.addEventListener('resize',()=>{
        this.drawMoneyPie()
      })

},
methods: {
      chartResize(){
          let erd=elementResizeDetectorMaker()
          erd.listenTo(this.$el,(element)=>{
          this.chart.resize()
          this.pieChart.resize()
          this.barChart.resize()
          this.circleChart.resize()
          this.circleChart2.resize()
        })
      },
      drawCircle(){
        this.circleChart=echarts.init(this.$refs.fixedD)
       
        let option = { }
        this.circleChart.setOption(option)
      },
}

有一个问题是我在使用图表时若使用flex布局,在子元素中使用felx:1来表示元素大小时,图表自适应不生效,改为width:50%用百分比表示自适应生效。

5.图表文字自适应

changeFontSize(res){
      let clientWidth = window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;
       if (!clientWidth) return;
       let fontSize = 100 * (clientWidth / 1920);
       return res*fontSize;
 },

在设置文字或者icon大小时调用该函数,可以使得图表里文字随屏幕大小而变化

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值