问题描述
我一直在试图弄清楚如何像文档演示页面中那样实现 NGX 图表的 x 轴时间线: https://swimlane.github.io/ngx-charts/#/ngx-charts/timeline-filter-bar-chart-demo
但是没有任何地方可以编码它是如何实现的,就像在其他 ngx 图表中一样。
我得到了 JSON 和基础知识:
name: 'Temperature',series: [
{ value: 22,name: '2021-06-01 10:45:00+00' },{ value: 33,name: '2021-06-01 11:14:44+00' },{ value: 11,name: '2021-06-01 13:45:00+00' },... ]
但我似乎没有像其他图表类型和功能那样没有 stackblitz 代码示例。
解决方法
据我所知,我认为数据必须是 JSON 格式
data = [
{
name: 'Temperature',series: [{
value: 22,name: '2021-06-01 10:45:00+00'
},{
value: 33,name: '2021-06-01 11:14:44+00'
},{
value: 11,name: '2021-06-01 13:45:00+00'
}
}]
<div *ngFor="let arr of data ">
<ngx-charts-bar-vertical
[view]="view"
[scheme]="colorScheme"
[results]="arr.series"
[gradient]="gradient"
[xAxis]="showXAxis"
[yAxis]="showYAxis"
[legend]="showLegend"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[xAxisLabel]="xAxisLabel"
[yAxisLabel]="yAxisLabel"
(select)="onSelect($event)">
</ngx-charts-bar-vertical>
</div>
自定义演示图表
“timeline-filter-bar-chart”是自定义图表组件的示例,您可以借助该库自行创建。
您可以在 framewok's repo 中找到源代码。