在highcharts中仅显示两个轴值

时间:2015-11-04 14:20:21

标签: highcharts

我想在此图表的y轴上仅显示2GB和4GB值(仅2个值)(请参阅jsFiddle):

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'bar'
        },
        title: {
            text: 'Stacked bar chart'
        },
        xAxis: {
            categories: ['Size']
        },
        yAxis: {
            min: 0,
            max: 4294967296,
            labels: {
                formatter: function() {
                    var maxElement = this.axis.max;
                    var kb = 1024, mb = 1048576, gb = 1073741824;
                    if (maxElement > gb) {
                        return (this.value / gb).toFixed(1) + " GB";
                    } else if (maxElement > mb) {
                        return (this.value / mb).toFixed(1) + " MB";
                    } else if (maxElement > kb) {
                        return (this.value / kb).toFixed(1) + " KB";
                    } else {
                      return (this.value) + " B";
                    }
                }
            },
            title: {
                text: ''
            }
        },
        tooltip: {
            formatter: function() {
                return '<b>' + this.series.name + '</b><br/>' + this.x + ': ' + filesize(this.y);
            }
        },
        legend: {
            reversed: false
        },
        plotOptions: {
            series: {
                stacking: 'normal'
            }
        },
        series: [{
            name: 'Versioned trees',
            data: [94371840]
        }, {
            name: 'Metadata',
            data: [115343360]
        }, {
            name: 'Data',
            data: [1395864371.2]
        }]
    });
});

有可能吗?

1 个答案:

答案 0 :(得分:3)

您可以使用tickPositions属性,如下所示:

tickPositions:[0, 1073741824 * 2, 1073741824 * 4]

如果您不包含0,它似乎不尊重min:0,但您可以通过添加隐藏0标签:

showFirstLabel: false

更新小提琴:

参考: