echart双折线,常用配置

/**
			 * 画双折线图
			 * @param container 容器
			 * @param titleName 标题
			 * @param xData x轴数据
			 * @param seriesNameOne 第一条折线图表名称
			 * @param seriesDataOne 第一条折线图表数据
			 * @param seriesNameTwo 第二条折线图表名称
			 * @param seriesDataTwo 第二条折线图表数据
			 * @param yAxisName  y轴名称
			 * @param legendNameArr  legend名称
			 * @colorArr 曲线颜色数据以及 legend颜色数组
			 * @yNumData y轴刻度设置,最小值,最大值,间隔值
			 */
			function drawDoubleLine(container, titleName, xData, seriesNameOne, seriesDataOne, seriesNameTwo, seriesDataTwo,yAxisName,legendNameArr,colorArr,yNumData) {
				var doubleLine = echarts.init(document.getElementById(container));
				doubleLineOption = {
					legend: {
						data: legendNameArr,
						color: colorArr,//legend自定义颜色值数组
						top:'1%',
						left:'70%',
						textStyle: { //图例文字的样式
							color: '#fff',
							fontSize: 12,
						},
					},
					tooltip: {
						trigger: 'axis',
						//指示器
						axisPointer: {
							type: 'line',
							lineStyle: {
								color: '#00eaff'
							}
						}
					},
					//标题样式
					title: {
						text: titleName,
						textStyle: {
							color: 'white',
						},
						left: 'center',
						show: true,
					},
					//图形位置
					grid: {
						left: '4%',
						right: '6%',
						bottom: '4%',
						top: 50,
						containLabel: true
					},
					xAxis: [{
						type: 'category',
						//x轴坐标点开始与结束点位置都不在最边缘
						boundaryGap: false,
						axisLine: {
							show: true,
							onZero: false,//x轴一直在最下面
							//x轴线样式
							lineStyle: {
								color: '#51fefe',
								width: 2,
								type: 'solid',
							}
						},
						//x轴字体设置
						axisLabel: {
							show: true,
							fontSize: 12,
							color: 'white'
						},
						data: xData
					}],
					yAxis: [{
						name: yAxisName,
						type: 'value',
						nameTextStyle: {
							color: '#ffffff',
							fontSize:12,
						},
						min: yNumData[0],//y轴最小值
						max: yNumData[1],//y轴最大值
						interval:yNumData[2],//刻度间隔
						//y轴字体设置
						axisLabel: {
							show: true,
							color: 'white',
							fontSize: 12,
							formatter: function(value) {
								if (value >= 1000) {
									value = value / 1000 + 'k';
								}
								return value;
							}
						},
						//y轴线设置显示
						axisLine: {
							show: false
						},
						//与x轴平行的线样式
						splitLine: {
							show: true,
							lineStyle: {
								color: '#51fefe',
								width: 1,
								type: 'dashed',
							}
						}
					}],
					series: [{
						name: seriesNameOne,
						type: 'line',
						smooth: true,
						lineStyle: {
							color: {
								type: 'linear',
								x: 0,
								y: 0,
								x2: 0,
								y2: 1,
								colorStops: [{
									offset: 0,
									color: colorArr[0] // 0% 处的颜色
								}, {
									offset: 1,
									color: colorArr[0] // 100% 处的颜色
								}],
								globalCoord: false
							},
							width: 2,
							type: 'solid',
						},
						//折线连接点样式
						itemStyle: {
							color: colorArr[0]
						},
						//折线堆积区域样式
						/* areaStyle: {
							color: '#004c5E'
						}, */
						data: seriesDataOne
					}, {
						name: seriesNameTwo,
						type: 'line',
						smooth: true,
						lineStyle: {
							color: {
								type: 'linear',
								x: 0,
								y: 0,
								x2: 0,
								y2: 1,
								colorStops: [{
									offset: 0,
									color: colorArr[1] // 0% 处的颜色
								}, {
									offset: 1,
									color: colorArr[1] // 100% 处的颜色
								}],
								globalCoord: false
							},
							width: 2,
							type: 'solid',
						},
						//折线连接点样式
						itemStyle: {
							color: colorArr[1],
						},
						//折线堆积区域样式
						/* areaStyle: {
							color: '#004c5E'
						}, */
						data: seriesDataTwo
					}]
				};
				doubleLine.setOption(doubleLineOption);
			}
			drawDoubleLine(
				'doubleLine', 
				'温度记录',
				['11-11', '11-12', '11-13', '11-14','11-15', '11-16', '11-17', '11-18'],
				'主卧室',
				[5, 10, 15, 5,20,10,20,10],
				'室外', 
				[10, 5, 5, 15,5,20,5,20],
				'温度(℃)',
				['主卧室','室外'],
				['#51fefe','#1673ff'],
				[-5,20,5],
			);

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

菜鸟也能逆袭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值