二_叔 2025-05-09 16:27 采纳率: 44.4%
浏览 71

echarts y轴太多,导致数据看上去很乱,该如何处理,使数据看的清晰一些

echarts y轴太多,导致数据看上去很乱,该如何处理,使数据看的清晰一些

img

option = option = {
    "title": {
        "left": "center",
        "top": 10
    },
    "legend": {
        "top": 40,
        "itemWidth": 10,
        "itemHeight": 5,
        "data": []
    },
    "tooltip": {
        "trigger": "axis",
    },
    "grid": {
        "left": "7%",
        "right": "7%",
        "bottom": "11%",
        "top": "12%",
        "show": true
    },
    "xAxis": {
        "type": "category",
        "data": ["1994-01", "1994-02", "1994-03", "1994-04", "1994-05"],
        "splitLine": {
            "show": true,
            "lineStyle": {
                "type": "dashed"
            }
        },
        "boundaryGap": false,
        "min": "dataMin",
        "max": "dataMax",
    },
    "yAxis": [
      {
        "type": "log",
        "name": "原油(吨/月)",
        "nameLocation": "end",
        "nameRotate": 90,
        "nameTextStyle": {
            "baseline": "middle",
            "align": "right",
            "verticalAlign": "bottom",
            "padding": [0, 10, 10, -10],
            "opacity": true
        },
        "axisLabel": {
            "rotate": 90,
            "showMaxLabel": false,
            "rich": {
                "d": {
                    "fontSize": 8,
                    "top": 20,
                    "verticalAlign": "top"
                }
            },
            "show": true
        },
        "logBase": 10,
        "position": "left",
        "offset": 0,
        "axisLine": {
            "show": false,
            onZero: false,
            "lineStyle": {
                "color": "#008000"
            }
        },
        "minorTick": {
            "show": true,
            "count": 5
        },
        "minorSplitLine": {
            "show": true,
            "lineStyle": {
                "type": "dashed",
                "color": "#e1e1e1"
            }
        },
        "splitLine": {
            "show": true,
            "lineStyle": {
                "type": "dashed",
                "color": "#e1e1e1"
            }
        }
    }, {
        "type": "log",
        "name": "天然气(万方/月)",
        "nameLocation": "end",
        "nameRotate": 90,
        "nameTextStyle": {
            "baseline": "middle",
            "align": "right",
            "verticalAlign": "bottom",
            "padding": [0, 10, 30, -10],
            "opacity": true
        },
        "axisLabel": {
            "rotate": 90,
            "padding": [0, 0, 20, 0],
            "showMaxLabel": false,
            "rich": {
                "dd": {
                    "fontSize": 8,
                    "top": 20,
                    "verticalAlign": "top"
                }
            },
            "show": true
        },
        "logBase": 10,
        "axisLine": {
            "show": false,
            onZero: false,
            "lineStyle": {
                "color": "#ff0000"
            }
        },
        "position": "left",
        "offset": 0,
        "minorTick": {
            "show": true,
            "count": 5
        },
        "minorSplitLine": {
            "show": false,
            "lineStyle": {
                "type": "dashed",
                "color": "#e1e1e1"
            }
        },
        "splitLine": {
            "show": false,
            "lineStyle": {
                "type": "dashed",
                "color": "#e1e1e1"
            }
        }
    }, {
        "type": "log",
        "logBase": 10,
        "name": "产水(万方/月)",
        "nameLocation": "end",
        "nameRotate": 90,
        "nameTextStyle": {
            "baseline": "middle",
            "align": "right",
            "verticalAlign": "bottom",
            "padding": [0, 10, 50, -10],
            "opacity": true
        },
        "axisLabel": {
            "rotate": 90,
            "padding": [0, 0, 40, 0],
            "showMaxLabel": false,
            "rich": {
                "ds": {
                    "fontSize": 8,
                    "top": 20,
                    "verticalAlign": "top"
                }
            },
            "show": true
        },
        "axisLine": {
            "show": false,
            onZero: false,
            "lineStyle": {
                "color": "#0000ff"
            }
        },
        "position": "left",
        "offset": 0,
        "minorTick": {
            "show": true,
            "count": 5
        },
        "minorSplitLine": {
            "show": false,
            "lineStyle": {
                "type": "dashed",
                "color": "#e1e1e1"
            }
        },
        "splitLine": {
            "show": false,
            "lineStyle": {
                "type": "dashed",
                "color": "#e1e1e1"
            }
        }
    }, {
        "type": "value",
        "position": "right",
        "name": "平均单井产量",
        "nameLocation": "end",
        "nameRotate": 90,
        "nameTextStyle": {
            "baseline": "middle",
            "align": "right",
            "verticalAlign": "bottom",
            "padding": [0, 20, -15, 0],
            "opacity": true
        },
        "offset": 0,
        "axisLine": {
          onZero: false,
            "show": false,
            "lineStyle": {
                "color": "#ca09c4"
            }
        },
        "axisLabel": {
            "padding": [-5, 0, 0, 0],
            "rotate": 90,
            "showMaxLabel": false,
            "formatter": "{value}",
            "show": true
        },
        "splitLine": {
            "show": false
        }
    }, {
        "type": "value",
        "name": "含水率(%)",
        "nameLocation": "end",
        "nameRotate": 90,
        "nameTextStyle": {
            "baseline": "middle",
            "align": "right",
            "verticalAlign": "bottom",
            "padding": [0, 20, -45, 20],
            "opacity": true
        },
        "position": "right",
        "offset": 0,
        "axisLine": {
          onZero: false,
            "show": false,
            "lineStyle": {
                "color": "#FF8C00"
            }
        },
        "axisLabel": {
            "rotate": 90,
            "padding": [25, 0, 0, 0],
            "showMaxLabel": false,
            "show": true,
            "formatter": "{value}"
        },
        "splitLine": {
            "show": false
        }
    }, {
        "type": "value",
        "axisLine": {
            "show": false
        },
        "axisLabel": {
            "show": false
        },
        "splitLine": {
            "show": false
        }
    }, {
        "type": "value",
        "position": "right",
        "name": "开油井数",
        "nameLocation": "end",
        "nameRotate": 90,
        "nameTextStyle": {
            "baseline": "middle",
            "align": "right",
            "verticalAlign": "bottom",
            "padding": [0, 20, -30, 0],
            "opacity": true
        },
        "offset": 0,
        "axisLine": {
          onZero: false,
            "show": false,
            "lineStyle": {
                "color": "#d7c825"
            }
        },
        "axisLabel": {
            "padding": [10, 0, 0, 0],
            "rotate": 90,
            "showMaxLabel": false,
            "formatter": "{value}",
            "show": true
        },
        "splitLine": {
            "show": true
        }
    }, {
        "type": "value",
        "position": "right",
        "name": "产液量",
        "nameLocation": "end",
        "nameRotate": 90,
        "nameTextStyle": {
            "baseline": "middle",
            "align": "right",
            "verticalAlign": "bottom",
            "padding": [0, 20, -60, 0],
            "opacity": true
        },
        "offset": 0,
        "axisLine": {
          onZero: false,
            "show": false,
            "lineStyle": {
                "color": "#51e881"
            }
        },
        "axisLabel": {
            "padding": [40, 0, 0, 0],
            "rotate": 90,
            "showMaxLabel": false,
            "formatter": "{value}",
            "show": true
        },
        "splitLine": {
            "show": false
        }
    }, {
        "type": "value",
        "position": "right",
        "name": "平均单井产液量",
        "nameLocation": "end",
        "nameRotate": 90,
        "nameTextStyle": {
            "baseline": "middle",
            "align": "right",
            "verticalAlign": "bottom",
            "padding": [0, 20, -75, 0],
            "opacity": true
        },
        "offset": 0,
        "axisLine": {
          onZero: false,
            "show": false,
            "lineStyle": {
                "color": "black"
            }
        },
        "axisLabel": {
            "padding": [55, 0, 0, 0],
            "rotate": 90,
            "showMaxLabel": false,
            "formatter": "{value}",
            "show": true
        },
        "splitLine": {
            "show": false
        }
    }, {
        "type": "value",
        "position": "right",
        "name": "气油比",
        "nameLocation": "end",
        "nameRotate": 90,
        "nameTextStyle": {
            "baseline": "middle",
            "align": "right",
            "verticalAlign": "bottom",
            "padding": [0, 20, -90, 0],
            "opacity": true
        },
        "offset": 0,
        "axisLine": {
          onZero: true,
            "show": false,
            "lineStyle": {
                "color": "#095738"
            }
        },
        "axisLabel": {
            "padding": [70, 0, 0, 0],
            "rotate": 90,
            "showMaxLabel": false,
            "formatter": "{value}",
            "show": true
        },
        "splitLine": {
            "show": false
        }
    }, {
        "type": "value",
        "position": "right",
        "name": "开井数",
        "nameLocation": "end",
        "nameRotate": 90,
        "nameTextStyle": {
            "baseline": "middle",
            "align": "right",
            "verticalAlign": "bottom",
            "padding": [0, 20, -105, 0],
            "opacity": true
        },
        "offset": 0,
        "axisLine": {
          onZero: true,
            "show": false,
            "lineStyle": {
                "color": "#00d9ff"
            }
        },
        "axisLabel": {
            "show": true,
            "padding": [85, 0, 0, 0],
            "rotate": 90,
            "showMaxLabel": false,
            "formatter": "{value}"
        },
        "splitLine": {
            "show": false
        }
    }],
    "dataZoom": [{
        "type": "inside",
        "startValue": "2015-01",
        "endValue": "2035-01",
        "filterMode": "filter",
        "show": false
    }, {
        "show": false,
        "type": "slider",
        "bottom": 30,
        "start": 0,
        "end": 100,
        "filterMode": "filter"
    }],
    "series": [
      {
        "name": "原油(吨/月)",
        "type": "line",
        "stack": "yy",
        "data": [120, 170, 200, 220, 206],
        "encode": {
            "x": 0,
            "y": 1
        },
        "yAxisIndex": 0,
        "itemStyle": {
            "color": "#008000"
        },
        "symbolSize": 5,
        "symbol": "circle",
        "lineStyle": {
            "width": 1
        },
        "xAxisIndex": 0,
        "markPoint": {
            "silent": true,
            "data": []
        }
    }, {
        "name": "含水率(%)",
        "type": "line",
        "data": [120, 230, 360, 403, 403],
      "symbol": "circle",
        "encode": {
            "x": 0,
            "y": 3
        },
        "yAxisIndex": 4,
        "itemStyle": {
            "color": "#FF8C00"
        },
        "symbolSize": 5,
        "lineStyle": {
            "width": 1
        }
    }, {
        "name": "产水(吨/月)",
        "type": "line",
        "stack": "dcs",
        "data": [340, 340, 230, 403, 540],
        "symbol": "circle",
        "encode": {
            "x": 0,
            "y": 3
        },
        "yAxisIndex": 2,
        "itemStyle": {
            "color": "#0000ff"
        },
        "symbolSize": 5,
        "lineStyle": {
            "width": 1
        }
    }, {
        "name": "开油井数(口)",
        "type": "line",
        "data": [23, 34, 23, 23, 12],
      "symbol": "circle",
        "encode": {
            "x": 0,
            "y": 3
        },
        "yAxisIndex": 4,
        "itemStyle": {
            "color": "#d7c825"
        },
        "symbolSize": 5,
        "lineStyle": {
            "width": 1
        }
    }, {
        "name": "平均单井产量(吨)",
        "type": "line",
        "data": [12, 32, 23, 34, 11],
          "symbol": "circle",
        "encode": {
            "x": 0,
            "y": 3
        },
        "yAxisIndex": 3,
        "itemStyle": {
            "color": "#ca09c4"
        },
        "symbolSize": 4,
        "lineStyle": {
            "width": 1
        }
    }, {
        "name": "天然气(万方/月)",
        "type": "line",
        "stack": "trq",
        "data": [12, 32, 34, 32, 31],
        "encode": {
            "x": 0,
            "y": 2
        },
        "yAxisIndex": 1,
        "itemStyle": {
            "color": "#ff0000"
        },
        "symbolSize": 4,
        "symbol": "circle",
        "lineStyle": {
            "width": 1
        },
        "markPoint": {
            "silent": true,
            "data": []
        }
    }, {
        "name": "产液量(吨)",
        "type": "line",
        "data": [12, 23, 12, 32, 43],
          "symbol": "circle",
        "encode": {
            "x": 0,
            "y": 3
        },
        "yAxisIndex": 4,
        "itemStyle": {
            "color": "#51e881"
        },
        "symbolSize": 5,
        "lineStyle": {
            "width": 1
        }
    }, {
        "name": "平均单井产液量(吨)",
        "type": "line",
        "data": [23, 23, 12, 12, 14],
          "symbol": "circle",
        "encode": {
            "x": 0,
            "y": 3
        },
        "yAxisIndex": 4,
        "itemStyle": {
            "color": "black"
        },
        "symbolSize": 5,
        "lineStyle": {
            "width": 1
        }
    }, {
        "name": "气油比(m³/t)",
        "type": "line",
        "data": [34, 23, 67, 45, 87],
          "symbol": "circle",
        "encode": {
            "x": 0,
            "y": 3
        },
        "yAxisIndex": 4,
        "itemStyle": {
            "color": "#095738"
        },
        "symbolSize": 5,
        "lineStyle": {
            "width": 1
        }
    }, {
        "name": "开井数(口)",
        "type": "line",
        "data": [78, 67, 56, 67, 67],
      "symbol": "circle",
        "encode": {
            "x": 0,
            "y": 3
        },
        "yAxisIndex": 4,
        "itemStyle": {
            "color": "#00d9ff"
        },
        "symbolSize": 5,
        "lineStyle": {
            "width": 1
        }
    }]
}

  • 写回答

7条回答 默认 最新

  • 阿里嘎多学长 2025-05-09 16:27
    关注

    阿里嘎多学长整理AIGC生成,因移动端显示问题导致当前答案未能完全显示,请使用PC端查看更加详细的解答过程

    解决方案

    echarts y轴太多,导致数据看上去很乱,可以通过以下方法来处理:

    1. 使用 categoryAxis:如果你的数据是分类数据,可以使用 categoryAxis 将 y 轴分割成多个小区间,每个小区间对应一个类别,这样可以减少 y 轴的数量。
    option = {
        "xAxis": {
            "type": "category",
            "data": ["类别1", "类别2", "类别3", ...]
        },
        "yAxis": {
            "type": "value",
            "splitLine": {
                "show": false
            }
        }
    };
    
    1. 使用 logScale:如果你的数据是数值数据,可以使用 logScale 将 y 轴转换为对数坐标系,这样可以减少 y 轴的数量。
    option = {
        "yAxis": {
            "type": "log",
            "splitLine": {
                "show": false
            }
        }
    };
    
    1. 使用 grid:可以使用 grid 将图表分割成多个小区间,每个小区间对应一个 y 轴,这样可以减少 y 轴的数量。
    option = {
        "grid": {
            "left": "3%",
            "right": "4%",
            "bottom": "3%",
            "containLabel": true
        }
    };
    
    1. 使用 tooltip:可以使用 tooltip 将数据的详细信息显示在 tooltip 中,这样可以减少 y 轴的数量。
    option = {
        "tooltip": {
            "trigger": "axis",
            "axisPointer": {
                "type": "shadow"
            }
        }
    };
    
    1. 使用 legend:可以使用 legend 将数据的类别显示在图表的右侧,这样可以减少 y 轴的数量。
    option = {
        "legend": {
            "data": ["类别1", "类别2", "类别3", ...],
            "orient": "vertical",
            "left": "center",
            "bottom": "10%"
        }
    };
    

    这些方法可以单独使用,也可以组合使用以达到最佳的效果。

    评论

报告相同问题?

问题事件

  • 创建了问题 5月9日