avd*_*per 5 typescript ngx-charts
我使用 ngx-chart 创建了一个图表。x 轴应填充年份。我的年份数组当前的值为:2020、2021、2022、2023。但是,当它显示在图表中时,它会自动添加 2020.5、2021.5、...
该值必须是数字才能按升序对年份进行排序。有没有办法阻止自动生成小数?
打字稿:
setChartValue(items: any[]): void {
let chartValues = [];
items.forEach((item) => {
chartValues.push({
'name': moment(item.purchaseDate, "DD/MM/YYYY").year(),
'value': item.purchasePrice
});
})
this.multi = [
{
'name': 'Purchase Summary',
'series': chartValues
}
];
}
Run Code Online (Sandbox Code Playgroud)
网页:
<ngx-charts-line-chart [view]="view"
[scheme]="colorScheme"
[results]="multi"
[gradient]="gradient"
[xAxis]="showXAxis"
[yAxis]="showYAxis"
[legend]="showLegend"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[xAxisLabel]="xAxisLabel"
[yAxisLabel]="yAxisLabel"
[autoScale]="autoScale"
[timeline]="timeline">
</ngx-charts-line-chart>
Run Code Online (Sandbox Code Playgroud)
我在 y 轴上有类似的情况可能会有所帮助。在图表的 html 中,我添加了 [yAxisTickFormatting]="yAxisTickFormattingFn"
在类定义中我添加了: public yAxisTickFormattingFn = this.yAxisTickFormatting.bind(this);
yAxisTickFormatting(value) {
return value;
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么这会改变任何东西,但它删除了 y 轴值的“.0”。
| 归档时间: |
|
| 查看次数: |
1347 次 |
| 最近记录: |