echarts 线性渐变方向

渐变使用方式:

1、new echarts.graphic.LinearGradient

2、type: linear

 拿官网的例子举例:

Examples - Apache ECharts

这个图中渐变核心部分:

  series: [
    {
      type: 'bar',
      showBackground: true,
      itemStyle: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
          { offset: 0, color: '#83bff6' },
          { offset: 0.5, color: '#188df0' },
          { offset: 1, color: '#188df0' }
        ])
      },
      emphasis: {
        itemStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: '#2378f7' },
            { offset: 0.7, color: '#2378f7' },
            { offset: 1, color: '#83bff6' }
          ])
        }
      },
      data: data
    }
  ]

 上面例子中用到了new echarts.graphic.LinearGradient,在方向是也是 四个值 ,分别为 x, y, x2, y2

x:为1 从左往右

y:为1 从上往下

x2:为1 从右往左

y2: 为1 从下往上

2、当我们需要使用渐变的时候还要再应用一次 echarts 才能拿到上面的 LinearGradient 类,有时候很不方便,所以一般才有直接用 type 来写

代码:

 showBackground: true,
      itemStyle: {
        color: {
          type: 'linear', // 线性渐变
          x: 0,             // x:  从左向右 1 ——> 0
          y: 0,             // y:  从上向下 1 ——> 0
          x2: 0,            // x2: 从右向左 1 ——> 0
          y2: 1,            // y2: 从下向上 1 ——> 0
          colorStops: [
            { offset: 0, color: '#83bff6' }, // 
            { offset: 0.5, color: '#188df0' },
            { offset: 1, color: '#188df0' }
          ]
        }
      },
      emphasis: {
        itemStyle: {
          color: {
            type: 'linear',
            x: 0, 
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              { offset: 0, color: '#2378f7' }, // offset:坐标为0处的颜色
              { offset: 0.7, color: '#2378f7' },
              { offset: 1, color: '#83bff6' } // offset:坐标为1处的颜色
            ]
          }
        }
      },
      data: data
    }
  ]

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
echarts中,可以通过itemStyle的color属性来实现颜色渐变效果。有两种方法可以实现颜色渐变。 方法一是使用线性渐变。可以通过设置type为'linear',然后设置x、y、x2、y2来确定渐变方向。接着使用colorStops数组来定义渐变的颜色,每个元素包含offset和color两个参数,offset表示位置,color表示颜色。最后设置globalCoord为false即可。这样就可以实现线性渐变效果。\[1\] 方法二是使用echarts内置的渐变色生成器echarts.graphic.LinearGradient。可以在itemStyle的color属性中使用这个生成器来定义渐变色。通过设置起止位置和颜色的渐变过程,可以实现颜色渐变效果。\[2\] 以上是两种常用的方法来实现echarts中的颜色渐变效果。具体的代码和效果可以参考官方文档和示例。 #### 引用[.reference_title] - *1* [echarts渐变色实现方法](https://blog.csdn.net/qq_44827865/article/details/120043930)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [echarts渐变色设置](https://blog.csdn.net/DZY_12/article/details/107610461)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值