<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Echarts图表</title>
<!-- 引入echarts.min.js -->
<script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>
</head>
<body>
<div id="main" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
var myChart = echarts.init(document.getElementById('main'));
var option = {
color: ['#88be1f', '#0088d2', '#dd3135'],
backgroundColor: '#061436',
// 表格位置
grid: {
left: 40,
right: 30,
top: 60,
bottom: 40,
},
// 提示框
tooltip: {
trigger: 'axis',
showContent: true,
formatter: function(params) {
var res = '<div><p>' + params[0].name + '</p></div>'
for (var i = 0; i < params.length; i++) {
res += '<p>' + params[i].marker + params[i].seriesName + ':' + params[i].value + '</p>'
}
return res;
}
},
// 图例
legend: {
top: 10,
textStyle: {
fontSize: 10,
color: 'rgba(255,255,255,.7)'
},
data: ['小型车', '中型车', '大型车']
},
xAxis: [{
name: '',
// 类目轴
type: 'category',
// 坐标轴两端空策略
boundaryGap: false,
axisLine: {
lineStyle: {
color: 'rgba(255,255,255,.2)'
}
},
splitLine: {
lineStyle: {
color: 'rgba(255,255,255,.1)'
}
},
axisLabel: {
color: "rgba(255,255,255,1)"
},
data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
}],
yAxis: [{
// 数值轴
type: 'value',
name: '',
min: 0,
max: 100,
interval: 20,
axisTick: {
show: false
},
axisLine: {
lineStyle: {
color: 'rgba(255,255,255,.3)'
}
},
splitLine: {
lineStyle: {
type: 'dashed',
color: 'rgba(255,255,255,.1)'
}
},
axisLabel: {
color: "rgba(255,255,255,1)"
}
}],
series: [{
name: '小型车',
type: 'line',
// 折线图变曲线图
smooth: true,
data: [20, 35, 30, 43, 50, 41, 50, 62, 22, 52, 22, 37]
},
{
name: '中型车',
type: 'line',
smooth: true,
data: [96, 97, 96, 97, 98, 90, 80, 92, 68, 65, 90, 82]
},
{
name: '大型车',
type: 'line',
smooth: true,
data: [82, 80, 65, 62, 42, 70, 57, 72, 78, 65, 62, 0]
}
]
};
myChart.setOption(option);
</script>
</body>
</html>
Echarts图表之带提示框的折线图(二)
最新推荐文章于 2024-06-20 14:37:29 发布