Home Forums Chart Support How to hide the secondary graph but not the axis label Reply To: How to hide the secondary graph but not the axis label

#22473

Satyabrata,

The issue you are facing is due to the interval, minimum and maximum thats being set to axis even when dataSeries are hidden. In this scenario, you may need to reset interval and range of axisY and axisY2 by setting them to null – when the dataSeries becomes visible. Please check out the below code-snippet to do the same.

for(var i = 0; i < chart.data.length; i++) {
  var dataSeries = chart.data[i];
  if (typeof (dataSeries.visible) === "undefined" || dataSeries.visible) {
    chart.options.data[i].visible = false;

    chart.options.axisY.viewportMinimum = chart.axisY[0].viewportMinimum;
    chart.options.axisY.viewportMaximum = chart.axisY[0].viewportMaximum;
    chart.options.axisY.interval = chart.axisY[0].interval;

    chart.options.axisY2.viewportMinimum = chart.axisY2[0].viewportMinimum;
    chart.options.axisY2.viewportMaximum = chart.axisY2[0].viewportMaximum;
    chart.options.axisY2.interval = chart.axisY2[0].interval;
  } else {
    chart.options.data[i].visible = true;

    chart.options.axisY.viewportMinimum = null;
    chart.options.axisY.viewportMaximum = null;
    chart.options.axisY.interval = null;

    chart.options.axisY2.viewportMinimum = null;
    chart.options.axisY2.viewportMaximum = null;
    chart.options.axisY2.interval = null;
  }
}

Please take a look at this updated JSFiddle for working sample.

The code that was shared previously was to help you towards solving your requirements. You can further modify code as per your requirement.


Vishwas R
Team CanvasJS