Highcharts、日期时间、时间戳。当轴的类型为 'datetime' 时,日期需要什么格式?
Highcharts, datetime, timestamp. What format of date needs when axis has type 'datetime'?
我是 Highcharts 的新手,遇到了一个问题。当 axis 类型为 'datetime' 时,它需要什么样的日期格式,只有时间戳?
例如:
const options: Options = {
chart: {
type: 'column',
},
xAxis: {
crosshair: false,
type: 'datetime',
title: {
text: 'test X,
},
labels: {
format: '{value:%m.%Y}', // here I formate to date
},
},
yAxis: {
title: {
text: 'test Y',
},
},
series: [
{
name: 'test 1',
data: [
[1483232400000, 1.4],
[1483491600000, 5.5],
],
},
{
name: 'test 2',
data: [
[1483232400000, 2.4],
[1483491600000, null],
],
},
],
};
但是我可以像这样用字符串传递数据吗?:
data: [
['2021/12/28', 1.4],
['2022/01/28', 1.3],...
或者像这样:
data: [
['28.12.2021', 1.4],
['28.01.2022', 1.3],...
根据文档:
type
The type of axis. Can be one of linear, logarithmic, datetime or
category. In a datetime axis, the numbers are given in milliseconds,
and tick marks are placed on appropriate values like full hours or
days. In a category axis, the point names of the chart's series are
used for categories, if not a categories array is defined.
您需要使用以毫秒为单位的时间戳:
series: [{
data: [
[new Date('2021/12/28').getTime(), 1.4],
[new Date('2022/01/28').getTime(), 1.3],
[new Date('2022/02/28').getTime(), 1.3]
]
}]
我是 Highcharts 的新手,遇到了一个问题。当 axis 类型为 'datetime' 时,它需要什么样的日期格式,只有时间戳? 例如:
const options: Options = {
chart: {
type: 'column',
},
xAxis: {
crosshair: false,
type: 'datetime',
title: {
text: 'test X,
},
labels: {
format: '{value:%m.%Y}', // here I formate to date
},
},
yAxis: {
title: {
text: 'test Y',
},
},
series: [
{
name: 'test 1',
data: [
[1483232400000, 1.4],
[1483491600000, 5.5],
],
},
{
name: 'test 2',
data: [
[1483232400000, 2.4],
[1483491600000, null],
],
},
],
};
但是我可以像这样用字符串传递数据吗?:
data: [
['2021/12/28', 1.4],
['2022/01/28', 1.3],...
或者像这样:
data: [
['28.12.2021', 1.4],
['28.01.2022', 1.3],...
根据文档:
type
The type of axis. Can be one of linear, logarithmic, datetime or category. In a datetime axis, the numbers are given in milliseconds, and tick marks are placed on appropriate values like full hours or days. In a category axis, the point names of the chart's series are used for categories, if not a categories array is defined.
您需要使用以毫秒为单位的时间戳:
series: [{
data: [
[new Date('2021/12/28').getTime(), 1.4],
[new Date('2022/01/28').getTime(), 1.3],
[new Date('2022/02/28').getTime(), 1.3]
]
}]