gpt4 book ai didi

javascript - 带有 'datetime' xAxis 的 Highcharts 图表 - 在向下钻取时使用类别

转载 作者:搜寻专家 更新时间:2023-11-01 04:56:55 24 4
gpt4 key购买 nike

有没有办法在主系列上为 xAxis 类型设置“日期时间”,但是当点击一个系列时,向下钻取是否使用那个时间的类别?

在这个 jsfiddle 示例 ( http://jsfiddle.net/kadams/3e3xqv7e/ ) 中,您可以看到当“类别”用作 xAxis 类型时,向下钻取数据正确地使用向下钻取系列名称“A”、“B”和“C” x 轴。但是当 xAxis 类型更改为“datetime”,并且毫秒时间用于“x”值代替主要系列的名称时,向下钻取的类别不显示“A”、“B” ',或'C'了。只是毫无意义的日期。

更新澄清 - 我更愿意使用“日期时间”类型而不是“类别”类型,并将值格式化为日期,因为当 x -轴很大:http://www.highcharts.com/errors/19 .我在下面的 fiddle 中给出了“类别”类型示例,只是为了证明当类型不是“日期时间”时,“A”、“B”、“C”确实可以正确显示。

$(function () {
$('#container').highcharts({
chart: {
type: 'column',
},
xAxis: {
type: 'category',
// type: 'datetime',
dateTimeLabelFormats: {
hour: '%l:%M %p'
}
},
legend: {
enabled: false
},
series: [{
name: 'Total',
colorByPoint: true,
data: [{
y: 8,
drilldown: 'Bob',
name: 'Bob', //used with 'category' xAxis type
x: 1420700400000 //used with 'datetime' xAxis type
}]
}],
drilldown: {
series: [{
id: 'Bob',
name: 'Bob',
data: [{
name: 'A',
y: 3
}, {
name: 'B',
y: 3
}, {
name: 'C',
y: 2
}]
}]
}
});
});

最佳答案

我已经找到了解决您问题的方法! Sebastian Bochan 给了我一些想法。您需要分离 xAxis 并为每个设置不同的类型。所以,在这里您必须将类别添加为 Highcharts's way .

xAxis: [{
id: 0,
type: 'datetime'
},
{
id: 1,
type: 'categories',
categories: data.categories
}
]

然后您必须在您的系列中添加此代码以将其与您的新 Axis 链接。

drilldown: {
series: [{
name: "test",
id: "test",
xAxis: 1, // <--- your desired X axis ID
data: [
[your data]
]
}]
}

您可能会在底部图表上看到细微的差别,但对我来说都适用。

希望对你有所帮助;)

关于javascript - 带有 'datetime' xAxis 的 Highcharts 图表 - 在向下钻取时使用类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27844786/

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