gpt4 book ai didi

javascript - 如何设置 Highcharts xAxis 在 yAxis 零值上的位置(负/正图表)?

转载 作者:行者123 更新时间:2023-11-28 01:42:45 25 4
gpt4 key购买 nike

我希望我的 xAxis 不在图表下方,而是在中间(在 yAxis 零值上)。

我还想要 xAxis 标签:

  • 在 xAxis 上方(当它是 negavite 值时)
  • 低于 xAxis(当它为值时
  • )

Wanted chart

这是我所拥有的:jsFiddle

$(function () {
$('#container').highcharts({
xAxis: {
showFirstLabel : true,
showLastLabel : true,
type : "category",
tickLength : 0,
lineWidth : 2
},

series: [{
data: [
{name : 'T1', y: 123},{name : 'T2', y: 152},{name : 'T3', y: -120},{name : 'T4', y: 0},{name : 'T5', y: 142},{name : 'T6', y: 212}
],
type : 'column'
}]
});
});
  • 是否有一种简单的方法可以做到这一点?
  • 如果没有,该怎么做?

谢谢。

<小时/>

解决方案:

感谢 Pawel Fus(谢谢,谢谢,谢谢),这是我的问题的解决方案:jsFiddle

$(function () {
$('#container').highcharts({
chart: {
renderTo: 'container',
type: 'column',
events: {
load: function () {
var xAxis = this.xAxis[0];
var serie = this.series[0];

for (var current_tick in xAxis.ticks) {
var tick = xAxis.ticks[current_tick];

if(serie.data[current_tick]){
if (serie.data[current_tick].y > 0) {
tick.label.attr({
y: tick.label.y + 18
});
}
}
}
}
}
},
xAxis: {
showFirstLabel : true,
showLastLabel : true,
type : "category",
tickLength : 0,
crossing:0,
opposite:true,
lineWidth : 2
},

series: [{
data: [
{name : 'T1', y: 123},{name : 'T2', y: 152},{name : 'T3', y: -120},{name : 'T4', y: 0},{name : 'T5', y: 142},{name : 'T6', y: 212}
],
type : 'column'
}]
});
});

最佳答案

给你的答案:

  1. 是的,这可以通过使用 Highcharts plugin 来实现。为此。

  2. 不支持此操作,您可以使用 chart.events.load 循环遍历 xAxis 中的所有标签,并根据相应类别的第一个系列中的值更新其位置

关于javascript - 如何设置 Highcharts xAxis 在 yAxis 零值上的位置(负/正图表)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20683223/

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