Pre loader

Javascript Stock Chart CategoryAxis date display minute ,second and microsecond

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

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.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies