EChart案例-折线面积渐变色

先看效果

图中的范围是个渐变色,option关键配置

 itemStyle: {
                    normal: {
                       areaStyle: {type: 'default'},
                       color: new echarts.graphic.LinearGradient(
                            0, 0, 0, 1,
                            [
                                {offset: 0, color: '#56ad66'},
                                {offset: 0.5, color: 'rgba(98, 199, 98, 0.3)'},
                                {offset: 1, color: 'rgba(98, 199, 98, 0.1)'}
                            ]
                        ),
                       borderColor:'#71df6f',//拐点边框颜色
                       borderWidth:2//拐点边框大小
                    }},

new echarts.graphic.LinearGradient生成渐变色对象,具体参数配置查阅官方API。

完整代码:

let data=[];
      for(var i=0;i<12;i++){
        data.push(Math.floor(Math.random()*1000+20))
      }

      let option = {
          title : {
              text: '',
          },
          tooltip : {
              trigger: 'axis',
              backgroundColor:' rgba(23, 99, 143, 0.75)' ,
              padding:[5,10],
              formatter(params){
               let point=params[0];
               return '2019年'+point.name+'月 : '+point.value
              }
          },
          legend: {
              data:['2019'],
              textStyle: {
                color: '#7aaab8',
                fontSize:14
              },

          },

          calculable : true,

          xAxis : [
              {
                name : '(月)',
                nameLocation: 'end',
                nameTextStyle:{
                color: '#a0d7de',
                fontSize:16,
                padding:[50, 0, 0, 10]
               },
                  type : 'category',
                  boundaryGap : false,
                  data : ['1','2','3','4','5','6','7','8','9','10','11','12'],
                  axisLine: {
                    show: false
                  },
                  axisTick: {
                      show: false
                  },
                  offset:10,
                  axisLabel: {
                      show:true,
                      textStyle: {
                        color: '#a0d7de',
                        fontSize:16
                      }
                  },
                  axisPointer:{ //基准线
                    lineStyle:{
                     color:'#52cdef'
                   }
                  }

              }
          ],


          yAxis : [
              {
                axisLabel: {
                  show:true,
                  textStyle: {
                    color: '#a0d7de',
                    fontSize:16
                  }
               },
               axisTick: {
                  show: false
              },
              axisLine: {
                  show: false
              },
              offset:10,
              splitLine: {
                show: true,
                lineStyle:{
                    type:'dashed',
                    color: ['#00f0ff']

                }
              }
            }
          ],
          series : [
              {
                  name:'2019',
                  type:'line',
                  smooth:true,
                  symbolSize: 10,   //设定实心点的大小
                  lineStyle:{
                    color:'#71df6f' //改变折线颜色
                  },
                  lineWidth:2,
                  itemStyle: {
                    normal: {
                       areaStyle: {type: 'default'},
                       color: new echarts.graphic.LinearGradient(
                            0, 0, 0, 1,
                            [
                                {offset: 0, color: '#56ad66'},
                                {offset: 0.5, color: 'rgba(98, 199, 98, 0.3)'},
                                {offset: 1, color: 'rgba(98, 199, 98, 0.1)'}
                            ]
                        ),
                       borderColor:'#71df6f',//拐点边框颜色
                       borderWidth:2//拐点边框大小
                    }},
                   data:data
              },

          ]
      };
      let myChart = echarts.init(document.getElementById('run-rain-line-chart'));
      myChart.setOption(option);

 

### ECharts `areaStyle` 属性详解 在 ECharts 中,`areaStyle` 是用于设置区域填充样式的属性。此样式通常应用于折线图面积图等图表类型中,可以增强视觉效果并使数据更加直观。 对于折线图而言,在配置项中通过指定 `series.areaStyle` 来开启或自定义该特性: ```javascript var option = { xAxis: {}, yAxis: {}, series: [{ name: '某指标', type: 'line', data: [120, 132, 101, 134, 90, 230, 210], areaStyle: {} // 开启默认的区域填充风格 }] }; ``` 为了实现更个性化的显示效果,还可以进一步调整 `areaStyle` 的具体参数来改变颜色透明度、阴影等细节[^1]。 #### 自定义 `areaStyle` 参数实例 下面是一个完整的例子展示了如何利用 `areaStyle` 创建带有渐变色背景的折线图: ```javascript option = { title: { text: '带渐变色折线图' }, tooltip: { trigger: 'axis' }, legend: { data: ['邮件营销'] }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, toolbox: { feature: { saveAsImage: {} } }, xAxis: { type: 'category', boundaryGap: false, data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] }, yAxis: { type: 'value' }, series: [ { name: '邮件营销', type: 'line', stack: '总量', areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ // 渐变方向从上到下 offset: 0, color: 'rgba(78, 165, 255, 0.8)' // 上方颜色 }, { offset: 1, color: 'rgba(78, 165, 255, 0.3)' // 下方颜色 }]) }, emphasis: { focus: 'series' }, data: [120, 132, 101, 134, 90, 230, 210] } ] }; ``` 在这个案例里,不仅设置了基本的颜色方案,还应用了一个由浅至深变化的垂直渐变作为填充色彩,使得图形看起来更为生动美观。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值