<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src='js/echarts.js'></script>
</head>
<body>
<div id="main" style="width: 800px; height: 600px"></div>
<script type="text/javascript">
// 基于准备好的dom,初始化ECharts图表
var myChart = echarts.init(document.getElementById("main"));
var option = { // 指定图表的配置项和数据
backgroundColor: 'rgba(128, 128, 128, 0.1)', //rgba设置透明度0.1
tooltip: {
trigger: 'axis'
},
legend: {
data: ['降水量', '蒸发量', '温度'],
left: 'center',
top: 12
},
toolbox: {
show: true,
orient: 'vertical',
x: 'right',
y: 'center',
feature: {
mark: { show: true },
dataView: { show: true, readOnly: false },
magicType: { show: true, type: ['line', 'bar', 'stack', 'tiled'] },
restore: { show: true },
saveAsImage: { show: true }
}
},
xAxis: [{
type: 'category',
data: ['1月', '2月', '3月', '4月', '5月', '6月',
'7月', '8月', '9月', '10月', '11月', '12月'
]
}],
yAxis: [{ // 设置2个Y轴之1:降水量、蒸发量
type: 'value',
name: '水量',
min: 0,
max: 200,
interval: 50,
axisLabel: {
formatter: '{value} ml'
}
},
{ // 设置2个Y轴之2:温度
type: 'value',
name: '温度',
min: 0,
max: 30,
position: 'right', // 设置y轴安置的位置
offset: 0, // 设置向右偏移的距离
axisLabel: {
formatter: '{value} °C'
}
}
],
series: [{
name: '降水量',
type: 'bar',
itemStyle: {
normal: {
color: 'pink'
}
}, // 设置柱形颜色
data: [2.6, 5.9, 9, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6, 2.3]
},
{
name: '蒸发量',
type: 'bar',
itemStyle: {
normal: {
color: '#D8BFD8'
}
}, // 设置柱形颜色
data: [2, 4.9, 7, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20, 6.4, 3.3]
},
{
name: '温度',
type: 'line',
yAxisIndex: 1, //指定使用第2个y轴
itemStyle: {
normal: {
color: 'red'
}
}, // 设置折线颜色
data: [2, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23, 16.5, 12, 6.2]
}
]
};
myChart.setOption(option); // 为echarts对象加载数据
</script>
</body>
</html>
echarts混搭图表
最新推荐文章于 2024-05-22 09:57:12 发布