只需要在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>