gpt4 book ai didi

javascript - Highcharts 刻度之间的空间不均匀

转载 作者:行者123 更新时间:2023-11-27 22:36:58 25 4
gpt4 key购买 nike

我有带有对数 y 轴的条形图。当我将 y 轴的 min 设置为接近 0(例如 0.1)时,刻度之间的间距看起来相等。但是,当我根据要求将 min 设置为 1000 时,图表会改变其行为,并且刻度之间的间距变得不均匀。这是一个例子https://jsfiddle.net/2vh9h2q3/ 。这是代码本身:

  new Highcharts.Chart({
"chart": {
"zoomType": "xy",
"renderTo": $('#container')[0],
"type": 'bar'
},
"title": {
"text": null
},
"subtitle": {
"text": null
},
"credits": {
"enabled": false
},
"exporting": {
"enabled": false
},
"xAxis": {
"categories": ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
"title": {
"text": null
},
"labels": {
"align": "left",
"x": 10
},
"lineWidth": 0,
"tickWidth": 0
},
"yAxis": {
"type": "logarithmic",
"min": 1000,
"labels": {
"formatter": function() {
return this.value % 1000 === 0 ? this.value / 1000 + "k" : this.value;
}
},
"title": {
"text": null
}
},
"tooltip": {
"useHTML": true,
"shadow": false
},
"plotOptions": {
"bar": {
"dataLabels": {
"enabled": false
}
},
"series": {
"cursor": "pointer"

}
},
"series": [{
"showInLegend": false,
"data": [4951,1200,0,0,196484,179580,0,0,0,324,87014, 11]
}]
});

我想将 min 保留为 1000,并在刻度之间获得均匀的空格。我尝试使用勾选选项,但没有成功

最佳答案

如果您想手动设置刻度的位置,使它们彼此之间的距离相同,可以使用tickPositions或tickPositioner:

"yAxis": {
"type": "logarithmic",
"min": 1000,
"labels": {
"formatter": function() {
return this.value % 1000 === 0 ? this.value / 1000 + "k" : this.value;
}
},
"tickPositions": [3, 4, 5, 6],
"title": {
"text": null
}
},

在这种情况下,tickPositions 数组中的数字是 10 的幂。因此,例如,如果您的值等于 3,您将看到 10^3 = 1000 值上的刻度。

在这里您可以找到它如何工作的示例: https://jsfiddle.net/2vh9h2q3/1/

您需要记住,如果您想使用对数轴,则不应使用小于或等于 0 的值。

关于javascript - Highcharts 刻度之间的空间不均匀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39017127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com