基本折线图
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#main {
width: 800px;
height: 500px;
}
</style>
</head>
<body>
<div id="main">
</div>
</body>
<script src="https://lib.baomitu.com/echarts/4.7.0/echarts.min.js"></script>
<script>
const dom = document.getElementById('main')
const myChart = echarts.init(dom)
const option = {
xAxis: {
data: ['html', 'css', 'js', 'canvas']
},
yAxis: {},
series: {
type: 'line',
data: [30, 20, 40, 100]
}
}
myChart.setOption(option)
</script>
</html>
折线图的几个相关配置
配置比较多,一样举几个常用的配置,详细的可以自行移步官方文档查看
smooth、itemStyle、areaStyle
series: {
type: 'line',
data: [30, 20, 40, 100],
smooth: true, // 折线平滑
itemStyle: { // 折线样式
color: 'pink'
},
areaStyle: { // 折线区域样式
color: '#00acec',
opacity: 0.2
}
}
boundaryGap
xAxis: {
data: ['html', 'css', 'js', 'canvas'],
boundaryGap: 0 // 两边区域的间距
}
symbol、symbolSize
series: {
type: 'line',
data: [30, 20, 40, 100],
smooth: true,
itemStyle: {
color: 'pink'
},
areaStyle: {
color: '#00acec',
opacity: 0.2
},
symbolSize: 20,
symbol: 'rect'
}