# Turn axes in Easy Chart on and off through scripting?

**URL:** <https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930>\
**Category:** Ignition\
**Created:** [July 14, 2016, 3:13pm UTC](https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930 "2016-07-14T15:13:32Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![MartinG](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@MartinG](https://forum.inductiveautomation.com/u/MartinG)\
**Post date:** [July 14, 2016, 3:13pm UTC](https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930/1 "2016-07-14T15:13:32Z")

</div>

I was wondering if it’s possible in the Easy Chart component, to turn axes on and off through scripting. Our client wants to be able to display just one axis specific to a tag instead of having multiple axes.

E.g. say like you are charting 5 or 6 tags with different axes. You want to just display 1 axis for a tag, and click on a button to display the axis for that tag. The button has the label ‘Axis for Tag 1’ on it (subsequent buttons display “Axis for Tag 2”, “Axis for Tag 3”, etc). Is there a way in the button’s script to tell Easy Chart to make the ‘Axis for Tag 1’ visible, while making the others invisible? If this is possible can whichever axis that is selected be displayed in the same spot, preferably to the left of the chart?

All of the plots would remain on the chart, but just one axis would be displayed pertaining to the tag that is selected.

If this is not possible are there any other possibilities, besides multiple axes?

Thanks.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 14, 2016, 3:34pm UTC](https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930/2 "2016-07-14T15:34:41Z")

</div>

Well, the base [Axis](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/axis/Axis.html) class in the JFreeChart library has a visible property, so it should be possible. Probably via configureChart().

---

<div class="post-metadata">

**Author:** ![SillyBear](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sillybear/32/9290_2.png) [@SillyBear](https://forum.inductiveautomation.com/u/SillyBear)\
**Post date:** [July 15, 2016, 3:05pm UTC](https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930/3 "2016-07-15T15:05:50Z")

</div>

I haven’t done it personally, but this might be helpful. setSeriesEnabled() might be worth playing around with as well, although it hides the entire line as well as the axis if it has no series.

[stackoverflow.com/questions/3973 … ries-yaxis](http://stackoverflow.com/questions/3973179/how-to-hide-jfreechart-xyseries-yaxis)

In Ignition land it should look like this. Obviously chart should be a reference to your chart.-

plot = chart.getPlot()  
range = plot.getRangeAxis()  
range.setVisible(0)

---

<div class="post-metadata">

**Author:** ![jsorlie](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jsorlie/32/3645_2.png) [@jsorlie](https://forum.inductiveautomation.com/u/jsorlie)\
**Post date:** [November 8, 2017, 1:32am UTC](https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930/4 "2017-11-08T01:32:43Z")

</div>

Thanks Phil for your hint. It led me to the JFree class documentation:

[http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/XYPlot.html](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/XYPlot.html)  
[http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/Plot.html](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/Plot.html)

My configureChart(self,chart) code example

> plot = chart.getPlot()  
> plot.setDomainGridlinesVisible(False)  
> plot.setRangeGridlinesVisible(False)  
> plot.setOutlineVisible(False)

---

<div class="post-metadata">

**Author:** ![dmdrendall](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@dmdrendall](https://forum.inductiveautomation.com/u/dmdrendall)\
**Post date:** [August 14, 2018, 12:25am UTC](https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930/5 "2018-08-14T00:25:08Z")

</div>

Hi Phil,  
Trying to make multiple Range Axes invisible on an EasyChart with a shared or combined Domain across several subplots. I might also need to manipulate the space the axes are taking up so as to give the chart more room.

I've isolated the "extraneous" Range Axes to the right side of each chart by manipulating the Axes.Data Position values.

Looking into this further I found that the the class the easyChart is a CombinedXYPlot (at least the way I have it configured) with a superclass of XYPlot. (if I have my terminology correct.) This is leading me to believe that I'll need to override a method of a super class to get at the axis visibility methods that are in the XYPlot class.

Any idea how to access getRangeAxisCount() method using jython syntax under the configureChart Extension Function?

I've tried extending the superclass with the subclass with an aim to use the "super" as indicated [here](https://docs.oracle.com/javase/tutorial/java/IandI/super.html), but Jython doesn't seem to play well with the way I'm implementing it as shown below:

> p = chart.plot  
> CombinedRangeXYPlot extends XYPlot  
> ra = super.plot.getRangeAxis()  
> print p  
> print ra

Any ideas how to get at these the methods in the superclass?

#Edit:

I've tried getting the methods available if I do:

> p = chart.getPlot  
> d = dir(p)

and get:

```auto
<bound method org.jfree.chart.JFreeChart.getPlot of org.jfree.chart.JFreeChart@100bf8c6>
[' __call__', ' __class__', ' __cmp__', ' __delattr__', ' __doc__', ' __get__',
 ' __getattribute__', ' __hash__', ' __init__', ' __new__', ' __reduce__',
 ' __reduce_ex__', ' __repr__', ' __setattr__', ' __str__', 'im_class',
 'im_func', 'im_self']

```

but still don't see an angle to get at methods as documented in the XPPlot class.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 14, 2018, 3:20pm UTC](https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930/6 "2018-08-14T15:20:10Z")

</div>

Accessing the super class’ methods from the subclass is as simple as calling them:  
`chart.getPlot().getRangeAxisCount()`; see the Javadocs for JFreeChart here:  
[http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/CombinedRangeXYPlot.html](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/CombinedRangeXYPlot.html)

---

<div class="post-metadata">

**Author:** ![dmdrendall](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@dmdrendall](https://forum.inductiveautomation.com/u/dmdrendall)\
**Post date:** [August 14, 2018, 7:09pm UTC](https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930/7 "2018-08-14T19:09:51Z")

</div>

Hi Paul,  
Tried accessing via the chaining method suggested a la:

> ra = chart.getPlot.getRangeAxisCount()  
> d = dir(ra)  
> print ra  
> print d

but got the method exception below:

```auto
ERROR [EasyChart-AWT-EventQueue-2] Error invoking extension method.
Traceback (most recent call last):
  File "<extension-method configureChart>", line 12, in configureChart
AttributeError: 'instancemethod' object has no attribute 'getRangeAxisCount'

```

Is it a scope thing inside an extension function?

Okay, so I imported XYPlot from org.jfree.chart.plot w/o complaint, but still trying to wrestle with feeding the methods the args they need. Such picky eaters, those java methods.

Thanks for the nudge in the right direction. The battle continues at least.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 14, 2018, 8:11pm UTC](https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930/8 "2018-08-14T20:11:56Z")

</div>

> [@dmdrendall](#):
>
> ra = chart.getPlot.getRangeAxisCount()

> AttributeError: 'instancemethod' object has no attribute 'getRangeAxisCount'

Right - you need to either use the JavaBeans `get<prop>`/`set<prop>` standard, in which case you must _call_ the function: `var = chart.getPlot().getRangeAxisCount()`  
**or**  
use Jython's auto-magic wrapper around bean properties, with direct address:  
`var = chart.plot.rangeAxisCount`

What you're doing there is going from the chart object to its `getPlot` _function_, then trying to call `getRangeAxisCount()` from the _function_, not the _result_ of the function.

---

<div class="post-metadata">

**Author:** ![dmdrendall](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@dmdrendall](https://forum.inductiveautomation.com/u/dmdrendall)\
**Post date:** [August 14, 2018, 10:01pm UTC](https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930/9 "2018-08-14T22:01:10Z")

</div>

Ah....I see. With the missing () for .getPlot, I'm only asking for the object, not the result of the function? (i.e. mixing my syntax, hence the reason for the error indicating the object has no attribute....) So now, with:

> p = chart.getPlot()  
> rac = p.getRangeAxisCount()  
> d = dir(rac)  
> print p  
> print d  
> print rac

I get:

```auto
org.jfree.chart.plot.CombinedDomainXYPlot@194864f
[' __abs__', ' __add__', ' __and__', ' __class__', ' __cmp__', ' __coerce__', ' __delattr__',
 ' __div__', ' __divmod__', ' __doc__', ' __float__', ' __floordiv__', ' __getattribute__',
 ' __getnewargs__', ' __hash__', ' __hex__', ' __index__', ' __init__', ' __int__',
 ' __invert__', ' __long__', ' __lshift__', ' __mod__', ' __mul__', ' __neg__', ' __new__', 
' __nonzero__', ' __oct__', ' __or__', ' __pos__', ' __pow__', ' __radd__', ' __rand__',
 ' __rdiv__', ' __rdivmod__', ' __reduce__', ' __reduce_ex__', ' __repr__', 
' __rfloordiv__', ' __rlshift__', ' __rmod__', ' __rmul__', ' __ror__',
 ' __rpow__', ' __rrshift__', ' __rshift__', ' __rsub__', ' __rtruediv__',
 ' __rxor__', ' __setattr__', ' __str__', ' __sub__', ' __truediv__', ' __xor__']
1

```

Now that I'm using the correct syntax, I'm surprised it only registers 1 range axis. Digging further...

Thanks for the syntax correction and awesome explanation!! Trying it in python wrapper out of curiosity, and for the practice. And voila. Magic indeed (assuming the case change only applies to the initial caps typically? --more reading to do)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 15, 2018, 12:31pm UTC](https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930/10 "2018-08-15T12:31:29Z")

</div>

The magic is provided by jython itself, inspired by Java NetBeans, like so:

- Methods with the signature `public SomeType getSomeName()` are exposed as readable property `someName`. Like so:  
`print someObject.someName`
- Methods with the signature `public void setSomeName(SomeType val)` make the above property writable. Like so:  
`someObject.someName = newvalue`
- As a special case, methods with the signature `public boolean isSomeName()` are exposed as readable boolean property `someName`.  
`print 'True' if someObject.someName else 'False'`

---

<div class="post-metadata">

**Author:** ![dmdrendall](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@dmdrendall](https://forum.inductiveautomation.com/u/dmdrendall)\
**Post date:** [August 16, 2018, 12:03am UTC](https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930/11 "2018-08-16T00:03:25Z")

</div>

Thanks for providing this very helpful context generalizations/translation. I’m trying to apply it to this proposed solution on stackoverflow:

[how-to-hide-jfreechart-xyseries-yaxis](https://stackoverflow.com/questions/3973179/how-to-hide-jfreechart-xyseries-yaxis#)

After applying your Introspection module to chart.plot of the configureChart extension function, it became clear that the method setVisible() is not in chart.plot (which appears to me to be a CombinedDomainXYPlot object).

Unless I’m missing something (again), if I’m to access the setVisible method on the Axis subclass of org.jfree.chart.axis, which is on a different “fork” of the superclass org.jfree.chart I’ll need to figure out:

How do you use a method in one subclass and use it in a “sibling” subclass? More literally, in my case, I’m trying to apply the setVisible() method to a CombinedDomainXY object.

I get the feeling I’m being encumbered by trying to do this with the configureChart extension function.

Seems too complicated to be trivial, but I can’t be the first one to want to “invisible” several y-axes on an easychart…

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 16, 2018, 10:19am UTC](https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930/12 "2018-08-16T10:19:05Z")

</div>

Based on the docs for [XYPlot](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/XYPlot.html), try something like this (note the check for a possible null ra):

```auto
xyplot = chart.plot
for rai in range(xyplot.rangeAxisCount):
	ra = xyplot.getRangeAxis(rai)
	if ra:
		ra.visible = False

```

---

<div class="post-metadata">

**Author:** ![dmdrendall](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@dmdrendall](https://forum.inductiveautomation.com/u/dmdrendall)\
**Post date:** [September 26, 2018, 7:47pm UTC](https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930/14 "2018-09-26T19:47:36Z")

</div>

Thx Phil.  
Been doing a ‘deep’ dive on encryption lately…deep for me.

Getting back to this, I found I had to drill down into the subplots to access the “visible” method on the various axes of each plot. I’ve got 3 subplots on my EasyChart, and wanted to give the user the ability to turn Y-axes on/off with a checkbox.

I tested your code provided above, but it would not work on my “CombinedDomainXYPlot”. After swimming through several layers of javadocs, I pressed your Introspect library into service to more quickly take stock of objects at various levels of the JFreeChart library, and their current values if any. Invaluable to me. Thank you.

The following code was the result for those looking to get started with controlling the Y-axes on a multiple subplot easychart:

```auto
## This code works to make invisible all range(y-axes) for 
## each subplot on the basis of the value of a checkbox in the header when
## the this function is called.
	
cb2 = self.parent.getComponent('Supply_Demand Header')\
.getComponent('PenCntrlContainer')\
.getComponent('CheckBox 2').selected

ch = chart
p = ch.plot
pt = p.plotType
sp = p.subplots
spa = sp.get(0)
spb = sp.get(1)
spc = sp.get(2)
for ria in range(spa.rangeAxisCount):
    if ria >= 0:
        spra = spa.getRangeAxis(ria)
        if spra:
            spra.visible = cb2

for rib in range(spb.rangeAxisCount):
    if rib >= 0:
        sprb = spb.getRangeAxis(rib)
        if sprb:
            sprb.visible = cb2

for ric in range(spc.rangeAxisCount):
    if ric >=0:
        sprc = spc.getRangeAxis(ric)
        if sprc:
            sprc.visible = cb2

```

Now that I have this general On/Off functionality working, I’m now trying to use one of the event handlers on the checkbox to call the configureChart Extension function, or possibly just importing all the necessary libraries and this code into that event listener on the checkbox.

The other improvement I’m pursuing is to give the user the ability to pick and choose which y-axes are showing, but this would require figuring out how EasyChart assigns indices to axes, and working through the logic to pick out the ones they want, or sort by a particular dataset heading using system.dataset.sort, but I’m not sure is sorting the AXES dataset will actually change the assigned axis indices. This exercise should help solve the problem of moving a trace’s order or layer, such that one is in front of or behind another regardless of which order they were entered when building the chart from scratch.

My first test will involve simply sorting the AXES dataset to see if the assigned indices within the subplot objects have changed accordingly. Then I can alter the ria, rib, and ric logical test values to select the axes I want for each subplot.

---

<div class="post-metadata">

**Author:** ![dmdrendall](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@dmdrendall](https://forum.inductiveautomation.com/u/dmdrendall)\
**Post date:** [October 10, 2018, 8:02pm UTC](https://forum.inductiveautomation.com/t/turn-axes-in-easy-chart-on-and-off-through-scripting/11930/15 "2018-10-10T20:02:11Z")

</div>

It appears that the indices are fixed (likely set at creation time). Despite sorting the AXES dataset, the indices remain unchanged.
