先把它们发布出来交流探讨.
<!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>
<!-- 引入echarts依赖包 -->
<script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.1.2/echarts.js"></script>
<style>
div{
width: 100%;
height:600px;
}
</style>
</head>
<body>
<!-- 准备一个容器:容器就是显示图标区域 -->
<div></div>
</body>
</html>
<script>
//基于准备好的DOM初始化echarts实例
let dom = document.querySelector('div');
//创建echarts实例
let mycharts = echarts.init(dom);
//指定图表的配置项与数据
mycharts.setOption(
option = {
tooltip: {
show: true,
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#283b56'
}
},
confine:true,
formatter: function(params) {
return "";
}
},
legend:{
show: true,
selected:{'a':true,'b':true,},
data:['a','b',],
},
grid: [{
"left": 120,
"right": 30,
"top": "45px",
"backgroundColor": "#ccc",
"height": "120"
}, {
"left": 120,
"right": 30,
"top": "180px",
"backgroundColor": "#ccc",
"height": "120"
}],
"xAxis": [{
"show": false,
"gridIndex": 0,
"type": "category",
"boundaryGap": false,
"data": ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
"axisPointer": {
"label": {
"margin": -20
}
}
}, {
"gridIndex": 1,
"type": "category",
"boundaryGap": false,
"data": ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
"axisPointer": {
"label": {
"margin": -20
}
}
}],
"yAxis": [{
//"name": "示例1",//Y轴左边的名字
"splitArea": {
"show": true
},
"nameLocation": "center",
"nameRotate": 0,
"nameGap": 40,
"gridIndex": 0,
"splitNumber": 4,
"type": "value",
}, {
//"name": "示例2",//Y轴左边的名字
"splitArea": {
"show": true
},
"nameLocation": "center",
"nameRotate": 0,
"nameGap": 40,
"gridIndex": 1,
"splitNumber": 4,
"type": "value",
}],
"series": [{
"data": [820, 932, 901, 934, 1290, 1330, 1320],
"name": "a",//图表中上部的开关按钮
"type": "line",
"smooth": true,
"xAxisIndex": 0,
"yAxisIndex": 0,
"markLine": {
"label": {
"normal": {
"position": "end",
"formatter": "{b}"
}
},
"data": [{
"lineStyle": {
"normal": {
"color": "#FDA428"
}
},
"xAxis": 195
}]
}
}, {
"data":[820, 932, 901, 934, 1290, 1330, 1320],
"name": "b",//图表中上部的开关按钮
"type": "line",
"smooth": true,
"xAxisIndex": 1,
"yAxisIndex": 1,
"markLine": {
"label": {
"normal": {
"position": "end",
"formatter": "{b}"
}
},
"data": [{
"lineStyle": {
"normal": {
"color": "#FDA428"
}
},
"xAxis": 195
}]
}
}
]
}
);
</script>
可以把以上源代码保存为html文件然后在浏览器里打开查看效果.
而我想达到的效果是,每个图表都有多条曲线并且想单独显示隐藏某条曲线.
有空再继续研究下.