Echarts 柱状图 颜色渐变 渐变规则

本文展示了如何使用Echarts创建具有颜色渐变效果的柱状图,通过LinearGradient实现从红色到黑色的渐变。代码示例中详细说明了配置项,包括数据、坐标轴设置和itemStyle的定义,帮助读者理解并应用到自己的项目中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Echarts 柱状图 颜色渐变 渐变规则

废话不多say 上代码

👍记得点赞哦 😄

👇大佬请看👇

  1. 颜色渐变控制:
color: new echarts.graphic.LinearGradient(
1, 0, 0, 0,
          [
            {offset: 0, color: '#D40F76'},
            {offset: 1, color: '#339DD9'}
          ]
        )
  1. 具体写法 Html
<div  id="even_reporting"></div>
  1. 具体写法 Js
方法名(){
 let even_reporting = echarts.init(document.getElementById("even_reporting"));
	option = {
		xAxis: [
		    {
		        type: 'category',
		        data: ['1','2','3','4','5'],
		        axisPointer: {
		            type: 'shadow'
		        }
		    }
		],
		yAxis: [
		    {
		        type: 'value',
		        name: '渐变',
		        min: 0,
		        max: 250,
		        interval: 50,
		    }
		],
		series: [{
		    name: '渐变',
		    type: 'bar',
		    data: [30, 60, 35, 150, 120,], 
		    itemStyle: {
		        normal: {
		            color: new echarts.graphic.LinearGradient(
		                1, 0, 0, 0, // 这里不同的排序会出现不同的效果   查看4 渐变规则
		                [
		                    {offset: 0, color: '#fa0020'},  // 红
		                    // 可以加0.2等
		                    {offset: 1, color: '#000000'},  // 黑
		                ]
		            )
		        },
		    },
		}]
  even_reporting.setOption(option);
}
   
  1. 效果:
    1,0,0,0

  2. 渐变规则
    0,0,0,1
    1,1,0,0
    0,0,1,1
    1,0,0,1
    0,1,1,0
    0,1,0,0
    0,0,1,0

都看👓完了,就👍1️⃣👇吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值