echarts5 折线图平滑曲线 渐变区域填充样式
说明
平时设计图经常会出现这种区域渐变的样式,所以记录下来以便后面使用。
效果图
安装echarts
yarn add echarts
配置代码
import * as echarts from 'echarts/core'
import {
LineChart
} from 'echarts/charts'
import {
GridComponent,
LegendComponent,
TooltipComponent,
TitleComponent
} from 'echarts/components'
import {
CanvasRenderer
} from 'echarts/renderers'
echarts.use(
[GridComponent, TitleComponent, LegendComponent, TooltipComponent,LineChart, CanvasRenderer]
)
const lineChart = echarts.init(document.querySelector('#echarts1'), 'macarons')
const chartOption = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'line'
}
},
grid: {
top: '8%',
bottom: '14%'
},
xAxis: {
axisLine: {
show: true,
lineStyle: {
color: '#16f1da'
}
},
data: ['8:00', '10:00', '12:00', '14:00', '16:00', '18:00'],
axisTick: {
alignWithLabel: true
}
},
yAxis: {
show: true,
splitLine: {
lineStyle: {
color: ['#1ce6d3']
}
},
axisLine: {
show: true,
lineStyle: {
color: '#0fe3cb'
}
}
},
series: [
{
label: {
show: true,
textStyle: {
color: '#ffffff'
}
},
symbol: 'none',
smooth: true,
lineStyle: {
color: '#7cf01d',
},
areaStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [{
offset: 0,
color: '#7cf01d'
}, {
offset: 1,
color: 'transparent'
}],
global: false
}
},
name: '入库',
type: 'line',
data: [5, 20, 36, 10]
},
{
label: {
show: true,
textStyle: {
color: '#ffffff'
}
},
symbol: 'none',
smooth: true,
lineStyle: {
color: '#f0dd4a',
},
areaStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [{
offset: 0,
color: '#f0dd4a'
}, {
offset: 1,
color: 'transparent'
}],
global: false
}
},
name: '出库库',
type: 'line',
data: [15, 20, 10, 36]
},
]
}
lineChart .setOption(chartOption)
|