How to show Date-Time values on the Y-axis in Angular Bar Charts?
Description
This article shows how to show date-time value in Y-axis in Angular Bar Charts.
Solution
Angular bar charts can be rendered by setting double values to the y-axis. However, Datetime values can be used on the y-axis to render the chart by specifying the milliseconds data, which is of double type, in the dataSource. Then, convert those milliseconds to datetime by using the value argument in the axisLabelRender event, and set the converted datetime to the text argument in the axisLabelRender event.
Code Snippet
The following example shows how to convert the milliseconds data to datetime in axisLabelRender event.
app.component.ts
axisLabelRender(args) {
if (args.axis.name == 'primaryYAxis') {
const date = new Date(args.value);
args.text = date.toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
});
}
}
app.component.html
<ejs-chart (axisLabelRender)="axisLabelRender($event)">
</ejs-chart>
The following screenshot illustrates the output of the above code snippet
Conclusion
I hope you enjoyed learning how to show the date-time value in Y-axis in Angular Bar Charts.
You can refer to our Angular Charts feature tour page to learn about its other features and documentation, and how to quickly get started for configuration specifications. You can also explore our Angular Charts example to understand how to create and visualize data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comment section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!