智者樂山山如畫, 仁者樂水水無涯。 從從容容一盃酒, 平平淡淡一盞茶。 細雨朦朧小石橋, 春風盪漾小竹筏。 夜無明月花獨舞, 腹有詩書气自華。 吾生有崖,也知無崖,以有崖逐無崖,殆也

Echarts 实线与虚线一起使用

 
    
    var seriesData = [{
            name: '蒸发量',
            type: 'bar',
            itemStyle: {
                normal: {
                    color: "blue",
                    barBorderColor: 'blue',
                    barBorderWidth: 3,
                    barBorderRadius: 0,
                    borderType: "solid"
                }
            },
            data: [11.0, 4.9, 7.0, 23.2, 25.6, 76.7, 11.6, 16.2, 32.6, 20.0, 
    {
        itemStyle: {
            normal: {
                color: '#fff',
                borderType: "dashed"
            }
        },
        value: 21,
    },
    {
        value: 22,
        itemStyle: {
            normal: {
                color: '#fff',
                borderType: "dashed"
            }
        }
    }],
        },
        {
            name: '平均温度',
            type: 'line',
            smooth: true,
            yAxisIndex: 1,
            itemStyle: {
                normal: {
                    color: "#000",
                    lineStyle: {
                        type: "solid",
                        width: 2
                    }
                }
            },
            data: [1100, 1202, 1303, 1405, 1300, 1020, 2030, 2340, 2300, "-", "-", "-"]
        },
        {
            name: '平均温度',
            type: 'line',
            smooth: true,
            yAxisIndex: 1,
            itemStyle: {
                normal: {
                    color: "#000",
                    lineStyle: {
                        type: "dotted",
                        width: 2
                    }
                }
            },
            data: ["-", "-", "-", "-", "-", "-", "-", "-", 2300, 1005, 1200, 602]
        }
    ]

    option = {
        tooltip: {
            show: true,
            trigger: 'axis',
            axisPointer: {
                //  type: 'cross',
                crossStyle: {
                    // color: '#999'
                }
            },
            formatter: function(params, ticket, callback) {
                console.log(params, 'params')
                var htmlStr = '';
                var valMap = {};
                for (var i = 0; i < params.length; i++) {
                    var param = params[i];
                    var xName = param.name; //x轴的名称  
                    var seriesName = param.seriesName; //图例名称  
                    var value = param.value; //y轴值  
                    var color = param.color; //图例颜色  
                    if (seriesName == "蒸发量") {
                        color = "blue";
                    } else if (seriesName == "降水量") {
                        color = "red"
                    }
                    //过滤无效值
                    if (value == '-') {
                        continue;
                    }

                    //过滤重叠值
                    if (valMap[seriesName] == value) {
                        continue;
                    }

                    if (i === 0) {
                        htmlStr += xName + '<br/>'; //x轴的名称  
                    }
                    htmlStr += '<div>';
                    //为了保证和原来的效果一样,这里自己实现了一个点的效果  
                    htmlStr += '<span style="margin-right:5px;display:inline-block;width:10px;height:10px;border-radius:5px;background-color:' + color + ';"></span>';

                    //圆点后面显示的文本  
                    // htmlStr += seriesName + ':' + value; 
                    if (seriesName == "平均温度") {
                        var value1 = "";
                        value = value + "";
                        if (value.length > 3) {
                            value1 = value.slice(0, 2) + ":" + value.slice(-2);
                        } else {
                            value1 = "0" + value.slice(0, 1) + ":" + value.slice(-2);
                        }
                        htmlStr += seriesName + ':' + value1;
                    } else {
                        htmlStr += seriesName + ':' + value;
                    }

                    htmlStr += '</div>';
                    valMap[seriesName] = value;
                }
                return htmlStr;
            }


        },
        grid: {
            bottom: "20%",
            left: 30,
            right: 30,
            containLabel: true
        },
        legend: {
            bottom: "10%",
            data: ['蒸发量',  '平均温度']

        },
        xAxis: [{
            axisLabel: {
                //  padding: [0, 110, 0,50], // 上右下左
                //  interval :10
                // margin :1
            },
            type: 'category',
            axisLine: {
                show: true,
                // onZero :false,
                // lineStyle:{width:1}
            },
            // nameLocation :"middle",
            data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
            axisPointer: {
                // type: 'shadow'
            },
            splitLine: { //网格线
                show: false
            },
            axisTick: { //y轴刻度线
                show: false,
                alignWithLabel: true,

            },
            boundaryGap: true
        }],
        yAxis: [{
                type: 'value',
                name: '水量',
                axisLabel: {
                    formatter: '{value} ml'
                },
                splitLine: { //网格线
                    show: false
                }
            },
            {
                type: 'value',
                name: '温度',
                axisLabel: {
                    formatter: '{value} °C'
                },
                splitLine: { //网格线
                    show: false
                },
                axisTick: { //y轴刻度线
                    show: false
                }
            },

        ],
        series: seriesData,
        dataZoom: [{
                type: 'slider',
                show: false,
                xAxisIndex: [0],
                start: 1,
                end: 100,
                bottom: "0",
            },
            {
                bottom: "10%",
                type: 'inside',
                xAxisIndex: [0],
                start: 1,
                end: 35
            }
        ],

    };

 

posted @ 2022-04-24 15:49  後生哥哥  阅读(87)  评论(0编辑  收藏  举报
智者樂山山如畫, 仁者樂水水無涯。 從從容容一盃酒, 平平淡淡一盞茶。 細雨朦朧小石橋, 春風盪漾小竹筏。 夜無明月花獨舞, 腹有詩書气自華。 吾生有崖,也知無崖,以有崖逐無崖,殆也