Javascript Stock Chart CategoryAxis date display minute ,second and microsecond
How to display date format HH:MM:SS.ssssss .
Can you please help me,
- sara uçar asked 2 years ago
- last edited 2 years ago
- You must login to post comments
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
- Andrew Burnett-Thompson answered 2 years ago
- You must login to post comments
Please login first to submit.