Anychart - 股票 - 正确日期显示的问题
Anychart - Stock - Problem with correct date display
我在 Angular 中使用 AnyChart(股票图表)正确显示日期时间时遇到问题。
有时 AnyChart 显示时间正确,但有时不正确 - 我不明白它取决于什么。
日期时间的错误格式是 '05 28 Mar 2019' 而相同的代码是 28 Mar 2019,05:00
我已经尝试过将带有时间的日期用作字符串、日期和时间戳。
有时小于 500 的刻度大小没问题。有时即使有几个刻度也不起作用。
有时当我放大图表时它会起作用。
代码示例:
draw(tickData: TickData, tickForChart: any[], container: ElementRef) {
const table = AnyCharts.data.table();
table.addData(tickForChart);
const mapping = table.mapAs({
x: 0,
open: 1,
high: 2,
low: 3,
close: 4
});
const chart = AnyCharts.stock();
const prices = chart.plot(0).candlestick(mapping);
prices.name(tickData.market.marketName);
prices.risingStroke('#3ba158');
prices.risingFill('#3ba158');
prices.fallingStroke('#fa1a20');
prices.fallingFill('#fa0f16');
chart.plot(0).xGrid().enabled(true);
chart.plot(0).yGrid().enabled(true);
chart.plot(0).yGrid().stroke("#dee2e6");
chart.title(this.getMarketName(tickData));
chart.container(container.nativeElement);
chart.scroller(true);
chart.draw();
container.nativeElement.style.height = '600px';
return chart;
}
有人遇到同样的问题吗?我该如何解决?
此外,我附加的图片格式错误。
wrong formatting
并且正确:
Correct formatting
例如它适用于数据的示例:
['2019-03-28T05:00:00', 511.53, 514.98, 505.79, 506.40],
['2019-03-28T05:30:00', 512.53, 514.88, 505.69, 510.34],
['2019-03-28T06:00:00', 511.83, 514.98, 505.59, 507.23],
['2019-03-28T06:30:00', 511.22, 515.30, 505.49, 506.47],
...
但数据失败:
['2015-12-24T08:13:00', 511.53, 514.98, 505.79, 506.40],
['2015-12-24T09:13:00', 512.53, 514.88, 505.69, 510.34],
['2015-12-24T10:13:00', 511.83, 514.98, 505.59, 507.23],
['2015-12-24T11:13:00', 511.22, 515.30, 505.49, 506.47]
...
您是否对标签应用了任何格式设置?请向我们提供代码,以便我们对其进行审核。无论如何,问题都可以通过格式设置来解决。例如,您可以使用以下行来格式化 xAxis 标签:
this.chart.plot(0).xAxis().labels().format('{%tickValue}{dateTimeFormat:dd MMM yyyy hh:mm}');
this.chart.plot(0).xAxis().minorLabels().format('{%tickValue}{dateTimeFormat:dd MMM yyyy hh:mm}');
发生这种情况是因为您将日期设置为不同的格式。如果你不仅要显示日期还要显示时间,你应该让所有的 x 值都有小时、分钟等。请检查这个 sample.
我在 Angular 中使用 AnyChart(股票图表)正确显示日期时间时遇到问题。
有时 AnyChart 显示时间正确,但有时不正确 - 我不明白它取决于什么。
日期时间的错误格式是 '05 28 Mar 2019' 而相同的代码是 28 Mar 2019,05:00
我已经尝试过将带有时间的日期用作字符串、日期和时间戳。
有时小于 500 的刻度大小没问题。有时即使有几个刻度也不起作用。
有时当我放大图表时它会起作用。
代码示例:
draw(tickData: TickData, tickForChart: any[], container: ElementRef) {
const table = AnyCharts.data.table();
table.addData(tickForChart);
const mapping = table.mapAs({
x: 0,
open: 1,
high: 2,
low: 3,
close: 4
});
const chart = AnyCharts.stock();
const prices = chart.plot(0).candlestick(mapping);
prices.name(tickData.market.marketName);
prices.risingStroke('#3ba158');
prices.risingFill('#3ba158');
prices.fallingStroke('#fa1a20');
prices.fallingFill('#fa0f16');
chart.plot(0).xGrid().enabled(true);
chart.plot(0).yGrid().enabled(true);
chart.plot(0).yGrid().stroke("#dee2e6");
chart.title(this.getMarketName(tickData));
chart.container(container.nativeElement);
chart.scroller(true);
chart.draw();
container.nativeElement.style.height = '600px';
return chart;
}
有人遇到同样的问题吗?我该如何解决?
此外,我附加的图片格式错误。
wrong formatting
并且正确:
Correct formatting
例如它适用于数据的示例:
['2019-03-28T05:00:00', 511.53, 514.98, 505.79, 506.40],
['2019-03-28T05:30:00', 512.53, 514.88, 505.69, 510.34],
['2019-03-28T06:00:00', 511.83, 514.98, 505.59, 507.23],
['2019-03-28T06:30:00', 511.22, 515.30, 505.49, 506.47],
...
但数据失败:
['2015-12-24T08:13:00', 511.53, 514.98, 505.79, 506.40],
['2015-12-24T09:13:00', 512.53, 514.88, 505.69, 510.34],
['2015-12-24T10:13:00', 511.83, 514.98, 505.59, 507.23],
['2015-12-24T11:13:00', 511.22, 515.30, 505.49, 506.47]
...
您是否对标签应用了任何格式设置?请向我们提供代码,以便我们对其进行审核。无论如何,问题都可以通过格式设置来解决。例如,您可以使用以下行来格式化 xAxis 标签:
this.chart.plot(0).xAxis().labels().format('{%tickValue}{dateTimeFormat:dd MMM yyyy hh:mm}');
this.chart.plot(0).xAxis().minorLabels().format('{%tickValue}{dateTimeFormat:dd MMM yyyy hh:mm}');
发生这种情况是因为您将日期设置为不同的格式。如果你不仅要显示日期还要显示时间,你应该让所有的 x 值都有小时、分钟等。请检查这个 sample.