SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components

0
0

Javascript Stock Chart CategoryAxis date display minute ,second and microsecond

How to display date format HH:MM:SS.ssssss .
Can you please help me,

Version
2.1.2301
  • You must to post comments
0
0

Hi Sara

See the Custom Labelprovider documentation. This shows you how you can format labels as anything you want (complete control over label formatting).

You can override label formatting as simply as this:

xAxis.labelProvider.formatLabel = (dataValue, format) => {
    const unixDateStamp = dataValue;
    return new Date(unixDateStamp * 1000).toLocaleDateString("en-GB", {
        month: "numeric",
        year: "numeric",
        day: "numeric"
    });
};

The label value is stored as a unix timestamp so you just need to format Unix Timestamp to HH:MM:SS.ssssss.

A function like this can convert a unix timestamp to milliseconds

export const formatUnixDateToHumanString = (unixTimestamp: number): string => {
    const date = new Date(unixTimestamp * 1000);
    const hours = date.getHours();
    const minutes = date.getMinutes();
    const seconds = date.getSeconds();
    const milliseconds = date.getMilliseconds();

    if (isNaN(hours) || isNaN(minutes) || isNaN(seconds)) { 
        return ""; 
    }

    return `${hours}:${minutes}:${seconds}:${milliseconds}`;
};

Let me know if this helps

Best regards
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.