Echarts带渐变色的折线图

只需要在series系列数据中加入渐进色即可实现上图效果。

                areaStyle: {
                    normal: {
                        //前四个参数代表位置 左下右上,如下表示从上往下渐变色 紫色到暗蓝色,
                        color: new echarts.graphic.LinearGradient(
                            0, 0, 0, 1,
                            [
                                { offset: 0, color: 'rgba(210, 35, 231, 1)' }, 
                                { offset: 1, color: 'rgba(76, 143, 243, 0)' }
                            ]
                        )
                    }
                }

代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>EChartsTest</title>
    <!-- 引入 echarts.js -->
	<script src="https://cdn.bootcss.com/echarts/4.2.1-rc1/echarts.min.js"></script>
</head>
<body>
    <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
    <div id="main" style="width:600px; height:300px; background-color:#143C50"></div>
	
    <script type="text/javascript">
	
    // 基于准备好的dom,初始化echarts实例
	var myChart = echarts.init(document.getElementById('main'));
	
    option = {
        tooltip : {  //提示框
            trigger: 'axis',
            axisPointer: {
                type: 'cross',
                label: {
                    backgroundColor: '#6a7985'
                }
            }
        },
        color: ['#d223e7', '#0882ac', ], 
        legend: {  //图例
            data: ['瑞星', '趋势'],
            itemHeight: 9,//改变圆圈大小
			//icon的值列举,
			//circle圆形, rect矩形, roundRect圆角矩形, triangle三角形, diamond菱形,
			//emptyCircle空心圆,emptyRectangle,emptyTriangle, emptyDiamond, pin大头针, arrow箭头, none无
            icon: "emptyCircle", //图标:空心圆样式,
            textStyle: {
                color: '#B0CEFC'        // 图例文字颜色
            }
        },
        grid: {
            x: 35,
            y: 38,
            x2: 0,
            y2: 26,
        },
        xAxis: {
            type: 'category', //类目
            data: ['6-4','7-1','7-2','7-3'],
            axisPointer: {  //坐标指示器
                type: 'shadow'  //阴影效果
            },
            axisLabel: {
                show: true,
                textStyle: {
                    color: '#B0CEFC',
                }
            },
        },
        yAxis: {
            type: 'value',
            interval: 10,
            axisLabel: {
                show: true,
                textStyle: {
                    color: '#B0CEFC',
                }
            },
            //网格样式
            splitLine: {
                show: true,
                lineStyle: {
                    color: ['#14364f', '#11233c', '#122b44', '#14314a', '#102c42'],//网格线色彩
                    width: 1,
                    type: 'solid'
                }
            },
        },
        series: [
            {
                name: '瑞星',
                type: 'line',
                areaStyle: {
                    normal: {
						//前四个参数代表位置 左下右上,如下表示从上往下渐变色 紫色到暗蓝色,
                        color: new echarts.graphic.LinearGradient(
                            0, 0, 0, 1,
                            [
                                { offset: 0, color: 'rgba(210, 35, 231, 1)' }, 
                                { offset: 1, color: 'rgba(76, 143, 243, 0)' }
                            ]
                        )
                    }
                },
                data: [20,35,20,20],
                lineStyle: {
                    normal: {
                        color: "#0882ac" //折线颜色蓝色
                    }
                }
            },
            {
                name: '趋势',
                type: 'line',
                areaStyle: {
                    normal: {
						//前四个参数代表位置 左下右上,如下表示从上往下渐变色 暗青色到亮青色,
                        color: new echarts.graphic.LinearGradient(
                            0, 0, 0, 1,
                            [
                                { offset: 0, color: 'rgba(12,180,250, 1)' }, 
                                { offset: 1, color: 'rgba(63, 208, 249, 0)' }
                            ]
                        )
                    }
                },
                data: [10,20,40,30],
                lineStyle: {
                    normal: {
                        color: "#2493d7"
                    }
                }
            }
        ]
    };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
		
    </script>
	
</body>
</html>

 

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值