You must be logged in to post your query.
Home › Forums › Chart Support › Dynamic indexLabelOrientation
Tagged: Bar charts, indexLabelOrientation
Hi,
I was wondering if it is possible to have a dynamically generated indexLabelOrientation. A customer uses bar charts that can have as many as 31 bars, one for each day of the month, or as low as 1, if there is data for one day only. When reaching a certain number of bars it is best to use vertical orientation, but when the quantity is low, the horizontal orientation is preferred.
It seems that indexLabelOrientation does not allow using functions to return different values depending on the data quantity. Is there any way to switch between vertical and horizontal orientation by having a threshold, say, 15 bars of data?
Thanks in advance. Juan
Juan,
You can set indexLabelOrientation property to “vertical” or “horizontal” depending on the number of datapoints and update the chart options. Please find the code snippet below,
if(chart.options.data[0].dataPoints.length > 15) chart.options.data[0].indexLabelOrientation = "vertical"; else chart.options.data[0].indexLabelOrientation = "horizontal"; chart.render();
Please take a look at this JSFiddle for working example.
— Adithya Menon Team CanvasJS
Thank you so much, Adithya, it works like a charm!
Best regards.
You must be logged in to reply to this topic. Login/Register