Home Forums Chart Support Dynamic indexLabelOrientation

Dynamic indexLabelOrientation

Viewing 3 posts - 1 through 3 (of 3 total)
  • #39480

    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

    #39483

    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.

    dynamically change index label orientation


    Adithya Menon
    Team CanvasJS

    #39485

    Thank you so much, Adithya, it works like a charm!

    Best regards.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.