How to turn off secondary Y Axis on a bar chart dynamically?

babbarbhangoo
edited February 11, 2022 in Analytics #1
<p>Hi,</p>
<p>I have a requirement to conditionally display a secondary Y Axis. I can either add a secondary Y axis dynamically via script or add it as default and remove it dynamically. </p>
<p>After researching a little bit I am able to remove the secondary Y Axis using the code below but I am not able to hide/remove the secondary Y axis scale. See attached pictures for better understanding</p>
<pre class="_prettyXprint _lang-js">
//find the secondary y-axis
yAxis2 = chart.getOrthogonalAxes(xAxis,true)[1];
var ySerieDef2 = yAxis2.getSeriesDefinitions().get(0);
//either this line can be used to set the y-axis visibility to false
yAxis2.getSeriesDefinitions().get(0).getSeries().get(0).setVisible(false);

//or this line can be used to remove it
yAxis2.getSeriesDefinitions().remove(0);
</pre>
<p>I am looking to either completely get rid of secondary y-axis i.e. hide the scale as well as the axis</p>
<p>or </p>
<p>hide the scale separate and hide the axis separate (as a continuation to my earlier code)</p>
<p> </p>
<p>Thanks in advance for the help!!</p>

Comments

  • <p>Added the following lines to my code to hide the scale.</p>
    <pre class="_prettyXprint _lang-js">
    yAxis2.getLineAttributes().setVisible(false);
    yAxis2.getMajorGrid().getLineAttributes().setVisible(false);
    yAxis2.getMinorGrid().getLineAttributes().setVisible(false);
    yAxis2.getMajorGrid().getTickAttributes().setVisible(false);
    yAxis2.getLabel().setVisible(false);
    </pre>