Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
75
Date Axis for Chart
posted

Hi, in the chart sample on candlesticks, the x-axis is given as a category axis and expects a string as a label. How do I display and format a date as a label instead?

Thanks,

Roy

Parents
  • 1775
    Suggested Answer
    posted

    Hi, KianMing Lai

    You can use the formatLabel option of the axis object for that purpose. The function specified with the option takes the current data item as an input argument and returns a formatted string to be plotted as axis label.

    Look at this example:   

    1. axes: [
    2.     {
    3.         name: "xAxis",
    4.         type: "categoryX",
    5.         formatLabel: function (item) {
    6.             var date = item.Timestamp;
    7.             return date.getMonth() + "/" +  date.getDate() + "/" + date.getFullYear();
    8.         }
    9.     }
    10. ]

    Here we configure a categoryX axis with an anonymous function for the formatLabel option. The function takes the Timestamp property of the data attached to the chart and creates string to be used for label.

    Cheers, Lazar

Reply Children