Articles in this section
Category / Section

How to display date-time values in tooltip for Angular Range Column Chart?

1 min read

Description

This article explains how to display date-time values in tooltips for an Angular Range Column Chart, specifically when the Y-axis represents time-based data(e.g., start and end times).

Solution

The chart component does not natively support displaying date-time values directly on the Y-axis. However, you can represent date-time values by providing the data in milliseconds (as double-type values) in the dataSource. These numeric values can then be converted to a readable date-time format in the tooltip using the tooltipRender event.

Implementation

The following code snippet demonstrates how to convert timestamp values on the Y-axis into formatted date-time strings within the tooltip.

app.component.ts

public tooltipRender(args: ITooltipRenderEventArgs): void {
   const intl: Internationalization = new Internationalization();
   const dateFormat: (date: Date) => string = intl.getDateFormat({ format: 'hh:mm a' }) as (date: Date) => string;
   const high: string = dateFormat(
   new Date(args.series.dataSource[args.point.index].y)
   );
   const low: string = dateFormat(
   new Date(args.series.dataSource[args.point.index].y1));
   args.text = `${args.point.x}: ${high} - ${low}`;
 } 

app.component.html

<ejs-chart (tooltipRender)="tooltipRender($event)">
</ejs-chart> 

Output

The tooltip will now display time values in a readable format such as 01:30 PM – 02:50 PM, even though the Y-axis values are provided as Date objects, which are internally handled as milliseconds.

image.png

Live Demo

View Sample in Stackblitz

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied