Echarts-双轴图

1、问题描述

利用Echarts制作一个折线图,条件是:三条折线,一条代表可利用率,另外两条代表数量。


2、实现源码

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>Echarts-双轴图</title>
		<link rel="shortcut icon" href="../js/echarts-2.2.7/doc/asset/ico/favicon.png">
		<script type="text/javascript" src="../js/echarts-2.2.7/doc/asset/js/jquery.min.js" ></script>
		<script type="text/javascript" src="../js/echarts-2.2.7/doc/example/www2/js/echarts-all.js" ></script>
		<style>
			body,html{
				width: 99%;
				height: 99%;
				font-family: "微软雅黑";
				font-size: 12px;
			}
			#double{
				width: 100%;
				height: 100%;
				font-family: "agency fb";
				font-weight: bolder;
			}
		</style>
		<script>
			$(function(){
				var chart = document.getElementById('double');  
                var echart = echarts.init(chart);  
                  
                var option = {
				    title : {
				        text: '可利用率',
				        subtext: '',
				        x: 'center',
				        align: 'right'
				    },
				    grid: {
				        bottom: 80
				    },
				    tooltip : {
				        trigger: 'axis',
				        axisPointer: {
				            animation: false
				        },
				        formatter: function (params) {
				            var res = params[0].name;
				            for (var i = 0, l = params.length; i < l; i++) 
				            {
				            	if(i==0)
				            	{
				            		res += '<br/>' + params[i].seriesName + ' : ' + params[i].value + "%";
				            	}
				            	else
				            	{
				            		res += '<br/>' + params[i].seriesName + ' : ' + params[i].value;
				            	}
				            }
				            
				            return res;
				        }
				    },
				    legend: {
				        data:['可利用率','A','B'],
				        x: 'left'
				    },
				    xAxis : [
				        {
				            type : 'category',
				            axisLabel: {
								rotate: 45
							},
				            boundaryGap : false,
				            axisLine: {onZero: false},
				            data : ['2016年1月', '2016年2月', '2016年3月', '2016年4月', '2016年5月','2016年6月','2016年7月','2016年8月','2016年9月','2016年10月','2016年11月','2016年12月'].map(function (str) {
				                return str.replace(' ', '\n')
				            })
				        }
				    ],
				    yAxis: [
				        {
				            name: '可利用率',
				            type: 'value',
				            max: 100,
				            axisLabel: {
			                  show: true,
			                  interval: 'auto',
			                  formatter: '{value} %'
			                }
				        },
				        {
				            name: 'A',
				            nameLocation: 'start',
				            type: 'value',
				            inverse: true
				        },
				        {
				            name: 'B',
				            nameLocation: 'start',
				            type: 'value',
				            inverse: true
				        }
				    ],
				    series: [
				        {
				            name:'可利用率',
				            type:'line',
				            hoverAnimation: false,
				            itemStyle: {
				            	normal: {
            						label : {
            							show:false,
            							position:'top',
            							formatter:'{c} %'
            						}
            					}
				            },
				            areaStyle: {
				                normal: {}
				            },
				            lineStyle: {
				                normal: {
				                    width: 1
				                }
				            },
				            data:[12,78,34,67,88,45,65,77,31,21,90,54]
				        },
				        {
				            name:'A',
				            type:'line',
				            yAxisIndex:1,
				            hoverAnimation: false,
				            areaStyle: {
				                normal: {}
				            },
				            lineStyle: {
				                normal: {
				                    width: 1
				                }
				            },
				            data: [1,4,5,8,3,2,7,6,9,2,4,3]
				        },
				        {
				            name:'B',
				            type:'line',
				            yAxisIndex:1,
				            hoverAnimation: false,
				            areaStyle: {
				                normal: {}
				            },
				            lineStyle: {
				                normal: {
				                    width: 1
				                }
				            },
				            data: [0,2,3,7,1,0,5,2,6,1,2,1]
				        }
				    ]
				};
                  
                echart.setOption(option);  
			});
		</script>
	</head>
	<body>
		<div id="double"></div>
	</body>
</html>
 


3、实现结果




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值