echarts的一些配置

本文详细介绍了Echarts的多种图表配置与使用方法,包括柱状图、饼图、弧形折线图、折线图阴影、自定义Y轴、颜色映射以及tooltip自动播放等功能。通过实例代码展示了如何实现这些效果,帮助读者掌握Echarts在数据可视化中的应用。
摘要由CSDN通过智能技术生成

获取省市区经纬度json ,DATAV.GeoAtolas 地址如下:

http://datav.aliyun.com/tools/atlas/

bigemap地图

http://www.bigemap.com/offlinemaps/demo/sllwshow.html#sllwshow

1、共有方法

  //柱状图
  showColumCategory: (that, el, xAxis, data, section) => {
    const myChart = echarts.init(document.getElementById(el));
    let option = {}
    option = {
      legend: { 
        show: true,
      },
      xAxis: {
        type: 'category',
        data: xAxis
      },
      yAxis: {
        type: "value",
        max: section && section[3].scoreTo,
        min: 0,
        splitNumber: 5,
        boundaryGap: [0, "100%"],
        axisLabel: {
          formatter: function (value) {
            var texts = [];
            let arr = section || []
            arr.find(item => {
              if (value > item.scoreFrom && value < item.scoreTo) {
                texts.push(item.levelName);
              }
            })
            if (value == 0) {
              texts.push('无');
            }
            return texts;
          }
        },
      },

      tooltip: {
        trigger: "axis",
        axisPointer: {
          width: '200px',
          type: "shadow",
          animation: false
        },
      },
      series: [{
        data: data,
        type: "bar",
        itemStyle: {
          normal: {
            color: function (params) {
              let value = params.value
              let colorArr = ["#73DEB3FF", "#1980FFCC", "#FEC402CC", "#FF635BCC"]
              let length = section && section.length || 0
              for (let i = 0; i < length; i++) {
                if (value > section[i].scoreFrom && value < section[i].scoreTo) {
                  return colorArr[i]
                }
              }
            },
            label: {
              show: false
            },
          }
        },
      }],
      grid: {
        left: 70,
        top: 45,
        right: 20,
        bottom: 60,
      }
    };
    // delete(option.yAxis.max);
    // delete(option.yAxis.min);
    myChart.setOption(option);
    that.charts.push(myChart);
    window.addEventListener('resize', () => {
      myChart.resize();
    })
  },

2、饼图显示注释,配置legend

在这里插入图片描述

option={
	legend: {
  	data: this.legend,
  	bottom:0,
  	left:'center',
  	textStyle:{
    	color:'#ffffff',
	  }
	},
}

3、弧形折线图,配置smooth

在这里插入图片描述

option={
  series: [{
      data: data,
      type: "line",
      smooth: true, //弧形
      itemStyle: {
        normal: {
          color: color,
          label: {
            show: true
          }
        }
      },
    }],
}

4、折线图阴影,配置areaStyle

在这里插入图片描述

option={
   areaStyle: {
     color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
         offset: 0,
         color: "#8cc3fbc9"//线的颜色
       },
       {
         offset: 1,
         color: "red"//阴影部分颜色
       }
     ])
   }
}

5、自定义Y轴,配置axisLabel

在这里插入图片描述
section为传进来的对象数组

option={
      yAxis: {
        type: "value",
        max: section && section[3].scoreTo,
        min: 0,
        splitNumber: 5,//分成及等分,即section的长度
        boundaryGap: [0, "100%"],//表示100%显示
        axisLabel: {
          formatter: function (value) {
            var texts = [];
            let arr = section || []
            arr.find(item => {
              if (value > item.scoreFrom && value < item.scoreTo) {
                texts.push(item.levelName);
              }
            })
            if (value == 0) {
              texts.push('无');
            }
            return texts;
          }
        },
      },
}

6、柱状图根据不同的值显示不同颜色,配置itemStyle

在这里插入图片描述

section为传进来的对象数组

option={
  series: [{
        data: data,
        type: "bar",
        itemStyle: {
          normal: {
            color: function (params) {
              let value = params.value
              let colorArr = ["#73DEB3FF", "#1980FFCC", "#FEC402CC", "#FF635BCC"]
              let length = section && section.length || 0
              for (let i = 0; i < length; i++) {
                if (value > section[i].scoreFrom && value < section[i].scoreTo) {
                  return colorArr[i]
                }
              }
            },
            label: {
              show: false
            },
          }
        },
      }],
}

7、tooltip自动播放

在这里插入图片描述

        let index = -1
        setInterval(function () {
            // 隐藏提示框
            myChart.dispatchAction({
                type: 'hideTip',
                seriesIndex: 0,
                dataIndex: index
            })
            // 显示提示框
            myChart.dispatchAction({
                type: 'showTip',
                seriesIndex: 0,
                dataIndex: index + 1
            })
            // 取消高亮指定的数据图形
            myChart.dispatchAction({
                type: 'downplay',
                seriesIndex: 0,
                dataIndex: index
            })
            // 高亮指定的数据图形
            myChart.dispatchAction({
                type: 'highlight',
                seriesIndex: 0,
                dataIndex: index + 1
            })
            if (index == 0) {
                myChart.dispatchAction({
                    type: 'downplay',
                    seriesIndex: 0,
                    dataIndex: 9
                })
            }
            index++
            if (index > 13) {
                index = -1
            }
        }, 2000)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

守望黑玫瑰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值