【问题标题】:In highcharts horizontal bar chart, I can't display the default ticks在 highcharts 水平条形图中,我无法显示默认刻度
【发布时间】:2020-12-11 16:46:26
【问题描述】:

这是javascript中的图形代码:

Highcharts.chart(here, {
        exporting: {
            enabled: false
        },
        chart: {
            type: "bar",
            //width: 300,
            //height: 60,
            width: 800,
            height: 160,
            margin: [0, 0, 0, 0]
        },
        title: {
            text: null
        },

        xAxis: {
            categories: ["Default category name"],
            title: {
                text: "testo uno"
            },
            //labels: {
            //    enabled: true
            //},
            opposite: true,
            tickInterval: 1
        },
        yAxis: {
            max: maximum,
            min: 0,
            title: {
                text: "testo due"
            }
            //labels: {
            //    enabled: true
            // }
        },
        tooltip: {
            enabled: true,
            valueSuffix: " millions"
        },
        plotOptions: {
            series: {
                pointPadding: 0.3,
                groupPadding: 0.1,
                animation: false
            }
        },
        legend: {
            enabled: false
        },
        credits: {
            enabled: false
        },
        series: [
            {
                name: "Name number one",
                data: [v1],
                color: "rgb(251, 147, 53)"
            },
            {
                name: "Name number two",
                data: [v2],
                color: "rgb(128, 128, 128)"
            },
            {
                name: "Name number three",
                data: [v3],
                color: "rgb(137, 196, 76)"
            }
        ]
    });

我希望默认刻度的标签显示在顶部。我似乎无法得到这些,我尝试将标签{启用}设置为 false,以及其他一些东西,但我似乎无法让刻度的标签显示在顶部。请查看随附的屏幕截图以查看我想要的刻度。有什么建议么?

【问题讨论】:

  • 弗拉基米尔,你会创建一个类似代码笔的东西吗?

标签: highcharts label horizontal-line


【解决方案1】:

您需要为标签腾出空间,例如保持默认边距并将yAxis.opposite 设置为true。

在 API 中我们可以阅读:

边距:数字,数组。

...

默认情况下没有边距。实际空间是动态的 根据轴标签、轴标题、标题、副标题的偏移量计算 和图例除了spacingTop、spacingRight、spacingBottom 和 spacingLeft 选项。

    yAxis: {
        opposite: true,
        ...
    }

现场演示: http://jsfiddle.net/BlackLabel/9rgjdesw/

API 参考:

https://api.highcharts.com/highcharts/chart.margin

https://api.highcharts.com/highcharts/xAxis.opposite

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-15
    相关资源
    最近更新 更多