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
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:
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
Hi Lazar,
Thank you for the reply.
Unfortunately, the solution is unable to work because the Date property in my code (equiv to your Timestamp) is not a recognised as a javascript Date.
It is databound to a C# DateTime type from the controller. The label is shown as something similar to /Date(1289923200000)/.
Do you have another solution to this?
Regards,
Hi, Roy
Please, excuse me for my late reply. I was off from the civilization for three weeks just as you posted your question, and then forgot to answer. It is my fault.
I think you have a neat solution for this situation: Bind your JSON to an igDataSource and then pass the data source to the chart control. The igDataSource is capable of converting dates formatted in the way you specified and convert them to JS dates. You only need to specify that a particular field is a date in the schema option of the data source. Here's an example how you can do this:
Note that everything that has no type specified is treated as a string.
Here follows how your formatLabel method will look like in that case:
Note how the Date member is accessed as an array element when the data comes from an igDataSource.