echarts混搭图表

<!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>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值