• 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",
                             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",
                             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;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:{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
                }
            ],
    
        };
  • 相关阅读:
    Docker _简单使用
    IDEA常见问题
    Linux安装JDK
    vitualbox网络设置链接
    MQ对比
    乐观锁和悲观所在数据库中的实现
    11.08 JS知识
    11.07知识整理
    11.06 知识整理
    本周知识整理
  • 原文地址:https://www.cnblogs.com/gxivwshjj/p/16186197.html
Copyright © 2020-2023  润新知