Skip to content

等间距设置yAxis的刻度 #6897

@suifengfengye

Description

@suifengfengye

One-line summary [问题简述]

设置了yAxis(type:value)的max后,max刻度就不是等间距的出现了。

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]:3.7.2
  • Browser version [浏览器类型和版本]:chrome/ 61.0.3163.91(正式版本) (32 位)
  • OS Version [操作系统类型和版本]:win7

Expected behaviour [期望结果]

目前想达到的效果是,我能根据刻度间距动态调整最大值。

image

ECharts option [ECharts配置项]

option = {
    "grid":{
        "left":20,
        "right":0,
        "top":"5%",
        "bottom":35,
        "containLabel":true
    },
    "tooltip":{
        "show":true,
        "textStyle":{
            "color":"#3d464a"
        },
        "backgroundColor":"#fff",
        "extraCssText":"box-shadow: 0 2px 12px rgba(49, 114, 149, 0.3);",
        "trigger":"axis"
    },
    "xAxis":[
        {
            "axisTick":{
                "show":false
            },
            "axisLine":{
                "lineStyle":{
                    "color":"#A4A8AB"
                }
            },
            "axisLabel":{
                "textStyle":{
                    "color":"#A4A8AB"
                },
                "interval":"auto"
            },
            "type":"category",
            "data":[
                "1月",
                "2月",
                "3月",
                "4月",
                "5月",
                "6月",
                "7月"
            ],
            "axisPointer":{
                "show":true,
                "lineStyle":{
                    "type":"dotted"
                },
                "handle":{
                    "show":true,
                    "size":38,
                    "margin":40,
                    "shadowBlur":0,
                    "shadowColor":"transparent"
                },
                "value":"7月"
            }
        }
    ],
    "yAxis":[
        {
            "type":"value",
            "axisTick":{
                "show":false
            },
            "axisLine":{
                "show":false
            },
            "axisLabel":{
                "textStyle":{
                    "color":"#A4A8AB"
                }
            },
            "splitLine":{
                "show":true,
                "lineStyle":{
                    "type":"dotted",
                    "color":"#e6e8ee"
                }
            },
            min: 0,
            max: (value) => {
                // 1900通过计算得出
                // 这里想做的是,能拿到刻度的间距大小,
                // 然后能够等间距地设置刻度,避免出现像1900不等间距的刻度,而是出现2100
                return 1900;
            }
        }
    ],
    "series":[
        {
            "code":"88bbc04a-1f23--3c2-9b86-0ed2d1f66c1b",
            "name":"当月目标(总计)",
            "type":"bar",
            "data":[
                300,
                400,
                500,
                600,
                700,
                800,
                900
            ],
            "yAxisIndex":0,
            "barMaxWidth":"40%",
            "label":{
                "normal":{
                    "show":false
                }
            },
            "itemStyle":{
                "emphasis":{
                    "opacity":0.8
                }
            },
            "markLine":{
                "data":[
                    {
                        "name":"辅助线1",
                        "yAxis":"1700"
                    }
                ],
                "label":{
                    "normal":{
                        "show":true,
                        "position":"start",
                        "rich":{
                            "t":{
                                "padding":[
                                    3,
                                    5
                                ],
                                "height":2
                            },
                            "a":{
                                "backgroundColor":"#E95950",
                                "color":"#fff",
                                "padding":[
                                    3,
                                    5
                                ],
                                "align":"right",
                                "height":10
                            }
                        }
                    }
                },
                "symbol":[
                    "",
                    ""
                ],
                "lineStyle":{
                    "normal":{
                        "color":"#E95950"
                    }
                }
            },
            "stack":"柱状堆积"
        },
        {
            "code":"984afcd0-7d79--ecc-8d84-7b179bd0b99e",
            "name":"当月实际(总计)",
            "type":"bar",
            "data":[
                20,
                40,
                40,
                98,
                24,
                47,
                80
            ],
            "yAxisIndex":0,
            "barMaxWidth":"40%",
            "label":{
                "normal":{
                    "show":false
                }
            },
            "itemStyle":{
                "emphasis":{
                    "opacity":0.8
                }
            },
            "stack":"柱状堆积"
        }
    ],
    "color":[
        "#716eed",
        "#b76ecb",
        "#AF97CB",
        "#DAC2DC",
        "#F2D1D1",
        "#EBA2D8",
        "#84CEED",
        "#8691CA"
    ]
}

Other comments [其他信息]

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleInactive for a long time. Will be closed in 7 days.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions