设置echarts中折线图中数据根据正负数显示不同区域背景色

本文介绍了如何在Echarts中为折线图的数据正负数设置不同的背景颜色。通过代码示例展示了设置大于0.01的原因,解释了若设置为0可能导致的coord属性为undefined的问题。

代码:

option = {
  backgroundColor: "#030A41",
  xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
    axisTick: {
      show: false,
    },
    axisLabel: {  //设置x轴坐标配置
            margin: 10,
            color: '#fff',  
            textStyle: {
                fontSize: 14
            },
        },
  },
  yAxis: {   //设置y轴坐标配置
    type: 'value',
    splitLine: {   
      show: true,  
      lineStyle: {
        color: '#132987',
      },
    },
    axisLabel: {  
            margin: 10,
            color: '#fff',  //y轴坐标文字颜色设置   
            textStyle: {
                fontSize: 14
            },
        },
  },
 visualMap: [
    {
      type: 'piecewise',
      show: false,
      pieces: [
        {
          lte: 0,   //数据<0配置
          color: 'rgba(255, 87, 87, 0.3)',  //设置区域背景色
        },
        {
          gte: 0.1,  //数据>0配置
          color: 'rgba(69, 215, 224, 0.3)',  //设置区域背景色
        },
      ],
      seriesIndex: 0,
    },
  ],
  series: [
    {
      data: [-100, -200, 224, 218, 135, 147, -260],
      type: 'line',
      areaStyle:{},   //区域背景色
      itemStyle: {
          normal: {
            lineStyle: {
              width: 2,
              color: "#9DD3E8"
            },
          },
        },
    }
  ]
};

效果图如下:
在这里插入图片描述

问题:
关于为什么这个地方要设置为大于0.01,如果设置为0,该echarts图会出现coord属性读取为undefined
在这里插入图片描述
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值