I have created a chart using ngx-chart. The x-axis should populate year. My array of year currently has values: 2020, 2021,2022,2023. However when it is displayed in the chart, it automatically adds 2020.5, 2021.5, ...
The value has to be number in order to sort the year in ascending order. Is there a way to prevent the decimal from being autogenerated?
Typescript:
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
}
];
}
Html:
<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>