echarts竖着折线,数据自动左右排序

说明

要求做表格类型竖着折线图

示例图

示例

HTML代码

<button id="btn1">某单位1按钮</button>
<button id="btn2">某单位2按钮</button>
<div id="main" style="width: 50%;height:400px;"></div>

JS代码

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="https://lib.baomitu.com/echarts/5.1.2/echarts.common.js"></script>
<script>
        $(function () {
            var jsonData={
                    backgroundColor: '#001534',
                    topData:{
                        planTitle:"计划值1",
                        planLineOne:"2017数据1",
                        planLineTwo:"2018数据2",
                        topPlanTipIsTrue:true
                    },
                    topColor:["rgba(0,255,91,0.5)","rgba(0,255,91,1)","#18daff","#fffa4a"],
                    yAxisText1:[
                        {value :-15,text:""},
                        {value :-15,text:"↓ 18",upIsTrue:false},
                        {value :-15,text:"↑ 4664",upIsTrue:true},
                        {value :-15,text:""},
                        {value :-15,text:"↓ 183",upIsTrue:false},
                        {value :-15,text:"↓ 184",upIsTrue:false},
                        {value :-15,text:""},
                        {value :-15,text:"↓ 185",upIsTrue:false},
                        {value :-15,text:"↑ 1855",upIsTrue:true},
                        {value :-15,text:"↑ 18555",upIsTrue:true},
                        {value :-15,text:""},
                        {value :-15,text:"↑ 18555",upIsTrue:true},
                        {value :-15,text:"↑ 1855",upIsTrue:true}
                    ],
                    yAxisText2:[
                        {value :-30,text:""},
                        {value :-30,text:"181"},
                        {value :-30,text:"1822"},
                        {value :-30,text:""},
                        {value :-30,text:"1833"},
                        {value :-30,text:"1844"},
                        {value :-30,text:""},
                        {value :-30,text:"1855"},
                        {value :-30,text:"1866"},
                        {value :-30,text:"1877"},
                        {value :-30,text:""},
                        {value :-30,text:"1811"},
                        {value :-30,text:"181111"}
                    ],
                    yAxis:{
                        name:"指标名称(单位)",
                        data:[
                            {value:'单位分类0',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(190,290,290,0.3)",padding:3}},
                            {value:'单位00单位00',textStyle:{align:"left"}}, 
                            {value:'单位10单位10单位10',textStyle:{align:"left"}}, 
                            {value:'单位分类1',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(250,250,250,0.3)",padding:3}}, 
                            {value:'单位20',textStyle:{align:"left"}}, 
                            {value:'单位30',textStyle:{align:"left"}}, 
                            {value:'单位分类2',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(250,250,250,0.3)",padding:3}}, 
                            {value:'单位40',textStyle:{align:"left"}}, 
                            {value:'单位50',textStyle:{align:"left"}}, 
                            {value:'单位60',textStyle:{align:"left"}}, 
                            {value:'单位分类3',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(250,250,250,0.3)",padding:3}},
                            {value:'单位70',textStyle:{align:"left"}},
                            {value:'单位80',textStyle:{align:"left"}},
                        ],
                        yAxisUnit:[
                            {yAxis: "单位分类0"},
                            {yAxis: "单位分类1"}, 
                            {yAxis: "单位分类2"}, 
                            {yAxis: "单位分类3"}
                        ]
                    },
                    xAxis:{
                        min:-30,
                        max:50,
                        markArea:{
                            nwIsTrue:true,
                            borderColor:"rgba(0,255,91,1)",
                            data: [
                                {startNum:"-15",endNum:"-30",startColor:"rgba(0,0,0,0.0)",endColor:"rgba(0,0,0,0.0)",text:"实际值\n▼"},
                                {startNum:"0",endNum:"-15",startColor:"rgba(0,0,0,0.0)",endColor:"rgba(0,0,0,0.0)",text:"增长\n▼"},
                                {startNum:"0",endNum:"5",startColor:"rgba(255,36,47,0.0)",endColor:"rgba(255,36,47,0.5)",text:"平均值\n▼"},
                                {startNum:"5",endNum:"25",startColor:"rgba(255,250,74,0.0)",endColor:"rgba(255,250,74,0.5)",text:"前25%\n▼"},
                                {startNum:"25",endNum:"40",startColor:"rgba(24,218,250,0.0)",endColor:"rgba(24,218,250,0.5)",text:"世界一流标准前\n12.5%\n▼"},
                                {startNum:"40",endNum:"50",startColor:"rgba(0,255,91,0.0)",endColor:"rgba(0,255,91,0.5)",text:"第一名\n▼"},
                            ]
                        },
                        markAreaData:[
                            {xAxis:-30},
                            {xAxis:-15},
                            {xAxis:5},
                            {xAxis:25},
                            {xAxis:40},
                            {xAxis:50}
//                          {xAxis:50,label: {borderColor: 'rgba(0,255,91,1)',borderWidth: 3}}
                        ]
                    },
                    seriesData:[
                        {
                            data:[
                                {value :null,ranking:"排名1",Percentage:"1%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}},
                                {value :14,ranking:"排名2",Percentage:"2%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}}, 
                                {value :12,ranking:"排名3",Percentage:"3%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}}, 
                                {value :8.25,ranking:"排名4",Percentage:"4%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}}, 
                                {value :4.5,ranking:"排名5",Percentage:"5%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
                                {value :12,ranking:"排名6",Percentage:"6%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
                                {value :13.5,ranking:"排名7",Percentage:"7%",Static:"1",symbolSize:0,label: {normal:{}},itemStyle:{}},
                                {value :15,ranking:"排名8",Percentage:"8%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}},  
                                {value :null,ranking:"排名9",Percentage:"9%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}}, 
                                {value :13,ranking:"排名10",Percentage:"10%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}}, 
                                {value :14,ranking:"排名11",Percentage:"11%",Static:"1",symbolSize:0,label: {normal:{}},itemStyle:{}},
                                {value :15,ranking:"排名12",Percentage:"12%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}}, 
                                {value :19,ranking:"排名13",Percentage:"13%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}}
                            ],
                            lineColor:"#18daff"
                        
                        },
                            {data:[
                                {value :null,ranking:"排名1",Percentage:"1%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}},
                                {value :24,ranking:"排名2",Percentage:"2%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}}, 
                                {value :22,ranking:"排名3",Percentage:"3%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}}, 
                                {value :31.5,ranking:"排名4",Percentage:"4%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}}, 
                                {value :4.1,ranking:"排名5",Percentage:"5%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
                                {value :22,ranking:"排名6",Percentage:"6%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
                                {value :23.5,ranking:"排名7",Percentage:"7%",Static:"1",symbolSize:0,label: {normal:{}},itemStyle:{}},
                                {value :25,ranking:"排名8",Percentage:"8%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}},  
                                {value :28,ranking:"排名9",Percentage:"9%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}}, 
                                {value :23,ranking:"排名10",Percentage:"10%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}}, 
                                {value :24,ranking:"排名11",Percentage:"11%",Static:"1",symbolSize:0,label: {normal:{}},itemStyle:{}},
                                {value :25,ranking:"排名12",Percentage:"12%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}}, 
                                {value :29,ranking:"排名13",Percentage:"13%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}}
                            ],
                            lineColor:"#fffa4a"
                        },
                    ]
            }
            var jsonOtherData={
                    backgroundColor: '#001534',
                    topData:{
                        planTitle:"计划值1",
                        planLineOne:"2017数据1",
                        planLineTwo:"2018数据2",
                        topPlanTipIsTrue:false
                    },
                    topColor:["rgba(0,255,91,0.5)","rgba(0,255,91,1)","#fff","blue"],
                    yAxisText1:[
                        {value :-15,text:""},
                        {value :-15,text:"↓ 18",upIsTrue:false},
                        {value :-15,text:"↓ 182",upIsTrue:false},
                        {value :-15,text:""},
                        {value :-15,text:"↑ 183",upIsTrue:true},
                        {value :-15,text:"↑ 184",upIsTrue:true},
                        {value :-15,text:""},
                        {value :-15,text:"↓ 185",upIsTrue:false},
                        {value :-15,text:"↑ 1855",upIsTrue:true},
                        {value :-15,text:"↑ 18555",upIsTrue:true},
                        {value :-15,text:""},
                        {value :-15,text:"↑ 18555",upIsTrue:true},
                        {value :-15,text:"↓ 1855",upIsTrue:false}
                    ],
                    yAxisText2:[
                        {value :-30,text:""},
                        {value :-30,text:"181"},
                        {value :-30,text:"1822"},
                        {value :-30,text:""},
                        {value :-30,text:"1833"},
                        {value :-30,text:"1844"},
                        {value :-30,text:""},
                        {value :-30,text:"1855"},
                        {value :-30,text:"1866"},
                        {value :-30,text:"1877"},
                        {value :-30,text:""},
                        {value :-30,text:"1811"},
                        {value :-30,text:"181111"}
                    ],
                    yAxis:{
                        name:"指标名称(单位)",
                        data:[
                            {value:'单位分类0',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(250,250,250,0.3)",padding:3}},
                            {value:'单位00单位00',textStyle:{align:"left"}}, 
                            {value:'单位10单位10单位10',textStyle:{align:"left"}}, 
                            {value:'单位分类1',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(250,250,250,0.3)",padding:3}}, 
                            {value:'单位20单位20单位20单位20',textStyle:{align:"left"}}, 
                            {value:'单位30',textStyle:{align:"left"}}, 
                            {value:'单位分类2',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(250,250,250,0.3)",padding:3}}, 
                            {value:'单位40',textStyle:{align:"left"}}, 
                            {value:'单位50',textStyle:{align:"left"}}, 
                            {value:'单位60',textStyle:{align:"left"}}, 
                            {value:'单位分类3',textStyle:{width:150,align:"left",rich:{},color:"#fff",fontWeight:"bold",fontSize:14,backgroundColor:"rgba(250,250,250,0.3)",padding:3}},
                            {value:'单位70',textStyle:{align:"left"}},
                            {value:'单位80',textStyle:{align:"left"}},
                        ],
                        yAxisUnit:[
                            {yAxis: "单位分类0"},
                            {yAxis: "单位分类1"}, 
                            {yAxis: "单位分类2"}, 
                            {yAxis: "单位分类3"}
                        ]
                    },
                    xAxis:{
                        min:-30,
                        max:50,
                        markArea:{
                            nwIsTrue:false,
                            borderColor:"rgba(0,255,91,1)",
                            data: [
                                {startNum:"-15",endNum:"-30",startColor:"rgba(0,0,0,0.0)",endColor:"rgba(0,0,0,0.0)",text:"实际值\n▼"},
                                {startNum:"0",endNum:"-15",startColor:"rgba(0,0,0,0.0)",endColor:"rgba(0,0,0,0.0)",text:"增长\n▼"},
                                {startNum:"0",endNum:"5",startColor:"rgba(255,36,47,0.0)",endColor:"rgba(255,36,47,0.5)",text:"平均值\n▼"},
                                {startNum:"5",endNum:"25",startColor:"rgba(255,250,74,0.0)",endColor:"rgba(255,250,74,0.5)",text:"前25%\n▼"},
                                {startNum:"25",endNum:"40",startColor:"rgba(24,218,250,0.0)",endColor:"rgba(24,218,250,0.5)",text:"世界一流标准前\n12.5%\n▼"},
                                {startNum:"40",endNum:"50",startColor:"rgba(0,255,91,0.0)",endColor:"rgba(0,255,91,0.5)",text:"第一名\n▼"},
                            ]
                        },
                        markAreaData:[
                            {xAxis:-30},
                            {xAxis:-15},
                            {xAxis:5},
                            {xAxis:25},
                            {xAxis:40},
                            {xAxis:50}
                        ]
                    },
                    seriesData:[
                        {
                            data:[
                                {value :null,ranking:"",Percentage:"",Static:"",symbolSize:0,label: {normal:{}},itemStyle:{}},
                                {value :34,ranking:"排名2",Percentage:"2%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}}, 
                                {value :32,ranking:"排名3",Percentage:"3%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}}, 
                                {value :32.5,ranking:"排名4",Percentage:"4%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}}, 
                                {value :33,ranking:"排名5",Percentage:"5%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
                                {value :32,ranking:"排名6",Percentage:"6%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},
                                {value :28.5,ranking:"",Percentage:"",Static:"",symbolSize:0,label: {normal:{}},itemStyle:{}},
                                {value :25,ranking:"排名8",Percentage:"8%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}},  
                                {value :null,ranking:"排名9",Percentage:"9%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}}, 
                                {value :23,ranking:"排名10",Percentage:"10%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}}, 
                                {value :null,ranking:"排名11",Percentage:"11%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}},
                                {value :null,ranking:"排名12",Percentage:"12%",Static:"0",symbolSize:8,label: {normal:{}},itemStyle:{}}, 
                                {value :32,ranking:"排名13",Percentage:"13%",Static:"1",symbolSize:8,label: {normal:{}},itemStyle:{}}
                            ],
                            lineColor:"#fff"
                        
                        },
                            {data:[
                                {value:null,ranking:"排名1",Percentage:"1%",Static:"0",symbolSize:0,label: {normal:{}},itemStyle:{}},
                                {value:25,ranking:"排名2",Percentage:"2%",Static:"0",symbolSize:8,label:{normal:{}},itemStyle:{}},
                                {value:20,ranking:"排名3",Percentage:"3%",Static:"1",symbolSize:8,label:{normal:{}},itemStyle:{}},
                                {value:32.5,ranking:"排名4",Percentage:"4%",Static:"0",symbolSize:0,label:{normal:{}},itemStyle:{}},
                                {value:45,ranking:"排名5",Percentage:"5%",Static:"0",symbolSize:8,label:{normal:{}},itemStyle:{}},
                                {value:26,ranking:"排名6",Percentage:"6%",Static:"1",symbolSize:8,label:{normal:{}},itemStyle:{}},
                                {value:26.5,ranking:"排名7",Percentage:"7%",Static:"0",symbolSize:0,label:{normal:{}},itemStyle:{}},
                                {value:27,ranking:"排名8",Percentage:"8%",Static:"1",symbolSize:8,label:{normal:{}},itemStyle:{}},
                                {value:4,ranking:"排名9",Percentage:"9%",Static:"1",symbolSize:8,label:{normal:{}},itemStyle:{}},
                                {value:29,ranking:"排名10",Percentage:"10%",Static:"0",symbolSize:8,label:{normal:{}},itemStyle:{}},
                                {value:27,ranking:"排名11",Percentage:"11%",Static:"0",symbolSize:0,label:{normal:{}},itemStyle:{}},
                                {value:25,ranking:"排名12",Percentage:"12%",Static:"1",symbolSize:8,label:{normal:{}},itemStyle:{}},
                                {value:39,ranking:"排名13",Percentage:"13%",Static:"0",symbolSize:8,label:{normal:{}},itemStyle:{}},
                            ],
                            lineColor:"blue"
                        },
                    ]
            }
            drawLine("main",jsonData)
            $("#btn1").click(function(){
                drawLine("main",jsonData)
            })
            $("#btn2").click(function(){
                drawLine("main",jsonOtherData)
            })
        });
        /*
         * drawLine(id,data)
         * 配置折线属性,默认series至少2组数据,否则无法绘制背景分割背景色和Y轴分割背景色
         * id:目标id string
         * data:json
         */
        function drawLine(id,data){
            var _data=data;
            //绘制头部
            var _tipdata=_data.topData;
            var _html=  "<div style='position: absolute;left: 4% ; top: 30px; color:#fff;'>";
                _html+= "   <div style='font-size:12px;'>"+_data.yAxis.name+"</div></div>";
                _html+= "<div id='topTitle' style='position: absolute;left: 50% ; top: 5px; color:#fff;'>";
                _html+= "   <div id='planTip' style='float:left;'><div style='width:20px;height:8px;background:"+_data.topColor[0]+";border:1px solid "+_data.topColor[1]+"; float:left; margin:7px 5px 0 0 ;'></div><div style='float:left;'>"+_tipdata.planTitle+"</div></div>";
                _html+= "   <div id='lineOneTip' style='float:left;'><div style='width:20px;height:3px;background:"+_data.topColor[2]+"; float:left; margin:10px 5px 0 15px ;'></div><div style='float:left;'>"+_tipdata.planLineOne+"</div></div>";
                _html+= "   <div id='lineTwoTip' style='float:left;'><div style='width:20px;height:3px;background:"+_data.topColor[3]+"; float:left; margin:10px 5px 0 15px ;'></div><div style='float:left;'>"+_tipdata.planLineTwo+"</div></div></div>";
            
            // 绘制图表。
            var myChart = echarts.init(document.getElementById(id));
            //头部div显示位置
            $("#topTitle").empty();
            $(myChart._dom.childNodes[0]).after(_html);
            //显示隐藏计划值tip
            if(_tipdata.topPlanTipIsTrue){
                $("#planTip").css("display","block");
            }else{
                $("#planTip").css("display","none");
            };
            //tip居中处理
            var marginLeft=$("#topTitle").width()/2;
            $("#topTitle").css("margin-left","-"+marginLeft+"px");
            
            //echar配置
            var option = {
                backgroundColor: _data.backgroundColor,
                legend: {
                    show:false
                },
                tooltip: {
                    show: false,
                    triggerOn: "none"
                },
                grid: {
                    left: '200',
                    right: '5%',
                    bottom: '5%',
                    containLabel: false
                },
                xAxis: {
                    type: 'value',
                    min: 0,
                    max: 50,
                    boundaryGap: true,
                    axisLabel: {
                        show: false,
                        textStyle: {
                            color:"#fff"
                        }
                    },
                    axisLine: {
                        show: false
                    },
                    axisTick: {
                        show: false
                    },
                    splitLine: {
                        show: false
                    }
                },
                yAxis: {
                    type: 'category',
                    inverse: true,
                    boundaryGap: true,
                    axisLine: {
                        show: false,
                    },
                    axisTick: {
                        show: false,
                        alignWithLabel: false
                    },

                    axisLabel: {
                        show: true,
                        margin:155.9,
                        backgroundColor:"rgba(50,50,50,0.3)",
                        textStyle: {
                                color:"#fff"
                        }
                    },
                    axisPointer: {
                        show: true,
                        type: "shadow",
                        label: {
                            show: true
                        }
                    },
                    triggerEvent: true, //坐标轴的标签是否响应和触发鼠标事件,默认不响应
                    data:[]
                },
                series: [
                    {
                        name: '数据1',
                        type: 'line',
                        smooth: false,
                        symbol: 'circle',
                        symbolSize: 8,
                        itemStyle:{
                            color:"#18daff"
                        },
                        lineStyle: {
                            normal: {
                                width: 1,
                                color:"#18daff",
                                shadowColor: 'rgba(0,0,0,0.4)',
                                shadowBlur: 10,
                                shadowOffsetY: 10
                            }
                        },
                        connectNulls: false, //开启连接空数据
                        label: {
                            normal: {
                                show: true,
                                color:"#18daff",
                                formatter: '{c}',
                                rich:{},
                                position: 'left' //值显示
                            }
                        },
                        markArea: {
                            data: [
                            [{
                                        xAxis: ''
                                    }, {
                                        xAxis: '',
                                        itemStyle: {
                                            color: {
                                                type: 'linear',
                                                x: 0,
                                                y: 0,
                                                x2: 1,
                                                y2: 0,
                                                colorStops: [{
                                                    offset: 0,
                                                    color: '' // 0% 处的颜色
                                                }, {
                                                    offset: 1,
                                                    color: '' // 100% 处的颜色
                                                }],
                                                globalCoord: false // 缺省为 false
                                            }
                                        }
                                    }

                                ],
                                [{
                                        xAxis: ''
                                    }, {
                                        xAxis: '',
                                        itemStyle: {
                                            color: {
                                                type: 'linear',
                                                x: 0,
                                                y: 0,
                                                x2: 1,
                                                y2: 0,
                                                colorStops: [{
                                                    offset: 0,
                                                    color: '' // 0% 处的颜色
                                                }, {
                                                    offset: 1,
                                                    color: '' // 100% 处的颜色
                                                }],
                                                globalCoord: false // 缺省为 false
                                            }
                                        }
                                    }

                                ],
                                [{
                                        xAxis: ''
                                    }, {
                                        xAxis: '',
                                        itemStyle: {
                                            color: {
                                                type: 'linear',
                                                x: 0,
                                                y: 0,
                                                x2: 1,
                                                y2: 0,
                                                colorStops: [{
                                                    offset: 0,
                                                    color: '' // 0% 处的颜色
                                                }, {
                                                    offset: 1,
                                                    color: '' // 100% 处的颜色
                                                }],
                                                globalCoord: false // 缺省为 false
                                            }
                                        }
                                    }

                                ],
                                [{
                                    xAxis: ''
                                }, {
                                    xAxis: '',
                                    itemStyle: {
                                        color: {
                                            type: 'linear',
                                            x: 0,
                                            y: 0,
                                            x2: 1,
                                            y2: 0,
                                            colorStops: [{
                                                offset: 0,
                                                color: '' // 0% 处的颜色
                                            }, {
                                                offset: 1,
                                                color: '' // 100% 处的颜色
                                            }],
                                            globalCoord: false // 缺省为 false
                                        }
                                    }
                                }],
                                [{
                                    xAxis: ''
                                }, {
                                    xAxis: '',
                                    itemStyle: {
                                        color: {
                                            type: 'linear',
                                            x: 0,
                                            y: 0,
                                            x2: 1,
                                            y2: 0,
                                            colorStops: [{
                                                offset: 0,
                                                color: '' // 0% 处的颜色
                                            }, {
                                                offset: 1,
                                                color: '' // 100% 处的颜色
                                            }],
                                            globalCoord: false // 缺省为 false
                                        }
                                    }
                                }],
                                [{
                                    xAxis: ''
                                }, {
                                    xAxis: '',
                                    itemStyle: {
                                        color: {
                                            type: 'linear',
                                            x: 0,
                                            y: 0,
                                            x2: 1,
                                            y2: 0,
                                            colorStops: [{
                                                offset: 0,
                                                color: '' // 0% 处的颜色
                                            }, {
                                                offset: 1,
                                                color: '' // 100% 处的颜色
                                            }],
                                            globalCoord: false // 缺省为 false
                                        }
                                    }
                                }],
                                
                            ]
                        },
                        markLine: {
                            silent: true,
                            symbolSize: 0,
                            label: {
                                position: "start",
                                formatter: function(params) {
                                    return ""
                                }
                            },
                            lineStyle: {
                                type: "solid",
                                color: "rgba(250,250,250,0.3)",
                                width: "20"
                            },
                            data: [],
                            rich:{
                                blue: {color: 'blue'},
                                green: {color: 'green'},
                                red: {color: 'red'},
                                white: {color: 'white'}
                            }
                        },
                        data:[]
                    },
                    {
                        name: '数据2',
                        type: 'line',
                        symbol: 'circle',
                        smooth: false,
                        symbolSize: 8,
                        itemStyle:{
                            color:"#fffa4a"
                        },
                        lineStyle: {
                            normal: {
                                width: 1,
                                color:"#fffa4a",
                                shadowColor: 'rgba(0,0,0,0.4)',
                                shadowBlur: 10,
                                shadowOffsetY: 10
                            }
                        },
                        connectNulls: false, //开启连接空数据
                        label: {
                            normal: {
                                show: true,
                                fontSize: 8,
                                formatter: "{c}",
                                rich:{},
                                position: 'right' //值显示
                            }
                        },
                        markLine: {
                            silent: true,
                            symbolSize: 0,
                            label: {
                                position: "start",
                                formatter: function(params) {
                                    var value = params.value;
                                    return value
                                }
                                
                            },
                            lineStyle: {
                                type: "solid",
                                width: "0",
                                curveness: 1,
                                color:"#fff"
                            },
                            data: []
                        },
                        data:[]
                    },
                    {
                        name:"实际值",
                        type: 'line',
                        symbol: 'circle',
                        smooth: false,
                        symbolSize: 0.00000001,
                        itemStyle:{
                            color:"rgba(0,0,0,0)"
                        },
                        label: {
                            normal: {
                                show: true,
                                color:"green",
                                formatter: '{c}',
                                rich:{},
                                position: 'inside' //值显示
                            }
                        },
                        data:[]
                    },
                    {
                        name:"增长",
                        type: 'line',
                        symbol: 'circle',
                        smooth: false,
                        symbolSize: 0.00000001,
                        itemStyle:{
                            color:"rgba(0,0,0,0)"
                        },
                        label: {
                            normal: {
                                show: true,
                                color:"#fff",
                                formatter: '{c}',
                                rich:{},
                                position: 'inside' //值显示
                            }
                        },
                        data:[]
                    }
                ]
            };
            option.yAxis.data=_data.yAxis.data;
            option.xAxis.min=_data.xAxis.min;
            option.xAxis.max=_data.xAxis.max;
            //处理Y轴多列文字显示问题
            option.series[2].data=_data.yAxisText1;
            option.series[3].data=_data.yAxisText2;
            //折线图1
            option.series[0].name=_tipdata.planLineOne;
            option.series[0].data=_data.seriesData[0].data;
            option.series[0].itemStyle.color=_data.seriesData[0].lineColor;
            option.series[0].lineStyle.normal.color=_data.seriesData[0].lineColor;
            option.series[0].markLine.data=_data.yAxis.yAxisUnit;
            for(var j=0;j<_data.xAxis.markArea.data.length;j++){
                var leng=_data.xAxis.markArea.data.length;
                var _nwIsTrue=_data.xAxis.markArea.nwIsTrue
                option.series[0].markArea.data[j][0].xAxis=_data.xAxis.markArea.data[j].startNum;
                option.series[0].markArea.data[j][1].xAxis=_data.xAxis.markArea.data[j].endNum;
                option.series[0].markArea.data[j][1].itemStyle.color.colorStops[0].color=_data.xAxis.markArea.data[j].startColor;
                option.series[0].markArea.data[j][1].itemStyle.color.colorStops[1].color=_data.xAxis.markArea.data[j].endColor;
                //是否显示绿色标域的边框
                if(_nwIsTrue){
                    option.series[0].markArea.data[leng-1][1].itemStyle.color.colorStops[0].color=_data.xAxis.markArea.data[j].endColor;
                    option.series[0].markArea.data[leng-1][1].itemStyle.color.colorStops[1].color=_data.xAxis.markArea.data[j].endColor;
                    option.series[0].markArea.data[leng-1][1].itemStyle.borderWidth="3";
                    option.series[0].markArea.data[leng-1][1].itemStyle.borderColor=_data.xAxis.markArea.borderColor;
                }
            }
            //折线图2
            option.series[1].name=_tipdata.planLineTwo;
            option.series[1].data=_data.seriesData[1].data;
            option.series[1].itemStyle.color=_data.seriesData[1].lineColor;
            option.series[1].lineStyle.normal.color=_data.seriesData[1].lineColor;
            option.series[1].markLine.data=data.xAxis.markAreaData;
            option.series[1].markLine.label.formatter=function(params){
                var value = params.value;
                var y_val0=_data.xAxis.markArea.data[0].endNum;
                var y_text0=_data.xAxis.markArea.data[0].text;
                var y_val1=_data.xAxis.markArea.data[1].endNum;
                var y_text1=_data.xAxis.markArea.data[1].text;
                var _val0=_data.xAxis.markArea.data[2].endNum;
                var _text0=_data.xAxis.markArea.data[2].text;
                var _val1=_data.xAxis.markArea.data[3].endNum;
                var _text1=_data.xAxis.markArea.data[3].text;
                var _val2=_data.xAxis.markArea.data[4].endNum;
                var _text2=_data.xAxis.markArea.data[4].text;
                var _val3=_data.xAxis.markArea.data[5].endNum;
                var _text3=_data.xAxis.markArea.data[5].text;
                //处理顶部标文字
                if(value == y_val0){
                    value = "{white|"+y_text0+"}"
                }else if(value == y_val1){
                    value = "{white|"+y_text1+"}"
                }else if(value == _val0) {
                    value = "{blue|"+_text0+"}"
                } else if(value == _val1) {
                    value = "{green|"+_text1+"}"
                } else if(value ==_val2) {
                    value = "{red|"+_text2+"}"
                } else if(value == _val3) {
                    value = "{white|"+_text3+"}"
                }
                return value
            }
            option.series[1].markLine.label.rich={
                blue: {color: 'blue'},
                green: {color: 'green'},
                red: {color: 'red'},
                white: {color: 'white'}
            }
            //可通过谋属性或者值来格式化点上的文字,颜色,位置
            if(true){
                for(var n=0;n<2;n++){
                    var val1=[],val2=[];
                    //处理折线1上的点的大小,颜色问题
                    option.series[0].label.normal.position="left";
                    option.series[0].data.forEach(function(value,index,array){
//                      console.log(value)
                        var _val=value.value;
                        val1.push(_val);
                        var _symbolSize=value.symbolSize;
                        if(_val>0 && _val<5 && _symbolSize!=0){
                            value.itemStyle.color="red";
                            value.label.normal.position="left";
                            value.symbolSize=15;
                        }else if(_val>5 && _val<25 && _symbolSize!=0){
                            
                        }else if(_val>25 && _val<40 && _symbolSize!=0){
                            
                        }else if(_val>40 && _val<50 && _symbolSize!=0){
                            value.itemStyle.color="green";
                            value.label.normal.position="right";
                            value.symbolSize=15
                        }
                        
                    });
                    //处理折线2上的点的大小,颜色问题
                    option.series[1].label.normal.position="right";
                    option.series[1].data.forEach(function(value,index,array){
                        var _val=value.value;
                        val2.push(_val);
                        var _symbolSize=value.symbolSize;
                        if(_val>0 && _val<5 && _symbolSize!=0){
                            value.itemStyle.color="red";
                            value.label.normal.position="top";
                            value.symbolSize=15;
                        }else if(_val>5 && _val<25 && _symbolSize!=0){
                            
                        }else if(_val>25 && _val<40 && _symbolSize!=0){
                            
                        }else if(_val>40 && _val<50 && _symbolSize!=0){
                            value.itemStyle.color="green";
                            value.label.normal.position="right";
                            value.symbolSize=15
                        }
                        
                    });
                    //处理2组数据点上文字左右的排布问题
                    var _length=val1.length
                    if(_length==val2.length){
                        for(var i = 0; i < _length; i++) {
                            if(val1[i] <= val2[i]) {
                                option.series[0].data[i].label.normal.position="left";
                                if(option.series[0].data[i].itemStyle.color=="red"){
                                    option.series[0].data[i].label.normal.position="right";
                                }
                                option.series[1].data[i].label.normal.position="right";
                            }
                            else {
                                option.series[0].data[i].label.normal.position="right";
                                option.series[1].data[i].label.normal.position="left";
                            }
                        }
                    }
                    //格式化点上文字描述  
                    option.series[n].label.normal.formatter=function(params){
                        //console.log(params.data)
                        var _val=params.value;
                        var _symbolSize=params.data.symbolSize;
                        var _ranking=params.data.ranking;
                        var _Static=params.data.Static;
                        var _Percentage=params.data.Percentage;
                        var text = "";
                        var _color="";
                        if(_Static==0){
                            _Static="↓"
                            _color="red";
                        }else{
                            _Static="↑"
                            _color="green";
                        };
                        if(_symbolSize != 0) {
                            text = "{white|"+_ranking+"} {blue|"+_val+"}\n{"+_color+"|"+_Static+_Percentage+"}"
                        }
                        return text
                    };
                    option.series[n].label.normal.rich={
                        blue: {color: 'blue'},
                        green: {color: 'green'},
                        red: {color: 'red'},
                        white: {color: 'white'}
                    };
                }
            }
            //格式化Y轴多列文字
            option.series[2].label.normal.formatter=function(params){
                var _val = params.data.value;
                var _text = params.data.text;
                var _upIsTrue = params.data.upIsTrue;
                var _color = "green";
                if(_upIsTrue){
                    _color = "green";
                }else{
                    _color = "red";
                };
                _text = "{"+_color+"|"+_text+"}"
                return _text
            }
            option.series[2].label.normal.rich={
                green: {color: 'green'},
                red: {color: 'red'}
            };
            option.series[3].label.normal.formatter=function(params){
                var _val = params.data.value;
                var _text = params.data.text;
                return _text
            }
            //绘制图
            myChart.setOption(option, true);
        
//点击事件
//          myChart.on('click', function (params) {
//              //点击Y轴上的文字 注意给对应的Y轴开启:triggerEvent:true
//              if(params.componentType=="yAxis" && params.yAxisIndex=="0"){
//                  if(params.value=="单位00"){
//                      option.series[0].data=[34,32,null,33,35,null,39,33,38,null, 39,35]
//                  }else{
//                      option.series[0].data=[14,12,null,13,15,null,19,13,18,null, 19,15]
//                  }
//                  option.yAxis.axisPointer.value=params.value;
//                  myChart.setOption(option,true);
//              }
//             });
        }
        </script>
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 214,875评论 6 496
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,569评论 3 389
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 160,475评论 0 350
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,459评论 1 288
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,537评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,563评论 1 293
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,580评论 3 414
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,326评论 0 270
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,773评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,086评论 2 330
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,252评论 1 343
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,921评论 5 338
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,566评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,190评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,435评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,129评论 2 366
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,125评论 2 352

推荐阅读更多精彩内容