echarts 双色折线图


echarts虽然提供了很多样例,但是常常还是会遇到稍微特殊的需求,比如上图的双色折线图。

核心思路:画两个折线图data分别为 data: [10, 20, 26, "-", "-", "-", "-"],data: ["-", "-", 26, 30, 23, 10, 5],没有数值的点,自然就没有折线,最后拼出来一条两边双色的折线图了。

完整option如下:

	let contrast_chartOption = {
	    tooltip: {
	        show: false,
	        trigger: 'axis'
	    },
	    xAxis: {
	        type: 'category',
	        boundaryGap: false,
	        data: ['-50%', '-25%', '0%', '25%', '50%', '75%', '收益率'],
	        axisLine: {	
	            show: false,
	            lineStyle: {
	                color: "#999"
	            }
	        },
	        axisTick: {
	            show: false
	        },
	        axisLabel: {
	            interval:0,
	            show: true,
	            textStyle: {
	                fontSize: 24,
	                color: "#b2b2b2",
	                align: "center"
	            }
	        },
	        splitLine: {
	            show: true,
	            lineStyle: {
	            	width: 1,
	            	color: "#f1f1f1"
	            }
	        }	        
	    },
	    yAxis: {
	        type: 'value',
	        axisLine: {
	            show: false
	        },
	        axisTick: {
	            show: false
	        },
	        axisLabel: {
	            show: false,
	            textStyle: {
	                color: "#fff",
	                align: "left"
	            }
	        },
	        splitLine: {
	            show: false
	        }
	    },
	    series: [
	        {
	            name: '收益率',
	            type: 'line',
	            smooth:true,
	            symbol: 'none',
	            lineStyle:{
	            	normal: {
	            		width: 5,
	            		color: '#9991fa'
	            	}
	            },
	            itemStyle:{
	                normal: {
	                    color:'#3C89ED' ,
	                    lineStyle:'#3C89ED'	
	                }
	            },
	            data: [10, 20, 26, "-", "-", "-", "-"],	            
	            markPoint : {
	                symbol: 'image://../img/my-position.png',
	                symbolSize:135,
	                symbolOffset:[0, '-20%'],
	                showDelay:0,
	                itemStyle:{
	                    normal:{
	                        label:{
	                            show: false
	                        }
	                    }
	
	                },
	                data : [
	                    {name : '最高', value :26, xAxis: 2, yAxis: 26}//通过yAxis来控制markPoint的位置
	                ]
	            },
				markArea: {
					itemStyle :{
						normal :{
							color : '#eef6fe',
							borderColor: 'red',
							borderWidth: 0,
							opacity: 0.6
						},
						emphasis :{
							color : '#eef6fe'
						}
					},
					data: [
						[{
							xAxis: '2'
						}, {
							xAxis: '3'
						}]
					]
				}
	        },{
	            name: '收益率',
	            type: 'line',
	            smooth:true,
	            symbol: 'none',	
	            lineStyle:{
	            	normal: {
	            		width: 5 ,
	            		color: '#f0952b'
	            	}
	            },	            
	            itemStyle:{
	                normal: {
	                    color:'#EB1F10' ,
	                    lineStyle:'#EB1F10'
	
	                }
	            },
	            data: ["-", "-", 26, 30, 23, 10, 5]
	        }
	    ]
	};

echarts虽然提供了很多样例,但是常常还是会遇到稍微特殊的需求,比如上图的双色折线图。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值