# XY plot tick units

**URL:** <https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342>\
**Category:** Ignition\
**Created:** [December 16, 2017, 4:11am UTC](https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342 "2017-12-16T04:11:38Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![JNelson](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@JNelson](https://forum.inductiveautomation.com/u/JNelson)\
**Post date:** [December 16, 2017, 4:11am UTC](https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342/1 "2017-12-16T04:11:38Z")

</div>

I’m having difficulty figuring out how to set the tick unit size for the Y-axis of a chart (or X-axis).  
I am able to obtain the tick unit size, but I can’t figure out how to set it.

I found the attribute:

chart.getXYPlot().getRangeAxis().setTickUnit()

which takes 1 or 3 arguments. I assume 1 argument would be the tick size, and 3 arguments would be the lower bound, upper bound and tick size.

However, when I try something like:

chart.getXYPlot().getRangeAxis().setTickUnit(20.0)

I get an error stating that the argument  
“can’t be coerced to org.jfree.chart.axis.NumberTickUnit”

So how do I provide an argument that the attribute will take?

---

<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:** [December 17, 2017, 5:06am UTC](https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342/2 "2017-12-17T05:06:48Z")

</div>

Instead of:

> [@JNelson](#):
>
> chart.getXYPlot().getRangeAxis().setTickUnit(20.0)

try:

```auto
from org.jfree.chart.axis import NumberTickUnit
chart.getXYPlot().getRangeAxis().setTickUnit(NumberTickUnit(20.0))

```

---

<div class="post-metadata">

**Author:** ![JNelson](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@JNelson](https://forum.inductiveautomation.com/u/JNelson)\
**Post date:** [December 18, 2017, 3:43pm UTC](https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342/3 "2017-12-18T15:43:59Z")

</div>

Perfect!  
Thank you.  
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

---

<div class="post-metadata">

**Author:** ![JNelson](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@JNelson](https://forum.inductiveautomation.com/u/JNelson)\
**Post date:** [December 20, 2017, 2:40pm UTC](https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342/4 "2017-12-20T14:40:10Z")

</div>

Now, the question is:  
How do you get the chart to return back to automatic tick units, once they’ve been set manually?

---

<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:** [December 20, 2017, 4:22pm UTC](https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342/5 "2017-12-20T16:22:48Z")

</div>

Probably [`setAutoTickUnitSelection(True)`](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/axis/ValueAxis.html#setAutoTickUnitSelection-boolean-) or similar function on the ValueAxis.

---

<div class="post-metadata">

**Author:** ![ASF](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ASF](https://forum.inductiveautomation.com/u/ASF)\
**Post date:** [October 29, 2018, 12:21am UTC](https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342/6 "2018-10-29T00:21:26Z")

</div>

I’m trying to do the same thing but getting an error

```auto
trend = event.source.parent.getComponent('Easy Chart')
from org.jfree.chart.axis import NumberTickUnit
trend.getXYPlot().getRangeAxis().setTickUnit(NumberTickUnit(5))
```

AttributeError: ‘[com.inductiveautomation.factorypmi.application.com](http://com.inductiveautomation.factorypmi.application.com)’ object has no attribute getXYPlot()

I’m sure I’m missing something simple, but I can’t seem to find it.

---

<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:** [October 29, 2018, 1:14am UTC](https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342/7 "2018-10-29T01:14:42Z")

</div>

The EasyChart is not a [ChartPanel](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/ChartPanel.html) subclass like the Classic Chart. Its ChartPanel is nested one level in. Use .getChart() on the EasyChart to get it. Or do this in the configureChart() method, where the `chart` variable is exposed for you.

---

<div class="post-metadata">

**Author:** ![ASF](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ASF](https://forum.inductiveautomation.com/u/ASF)\
**Post date:** [October 29, 2018, 1:47am UTC](https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342/8 "2018-10-29T01:47:02Z")

</div>

```auto
trend = event.source.parent.getComponent('Easy Chart')
from org.jfree.chart.axis import NumberTickUnit
trend.getChart().getXYPlot().getRangeAxis().setTickUnit(NumberTickUnit(5))
```

gives the error:

```auto
AttributeError: 'com.inductiveautomation.factorypmi.application.com' object has no attribute getChart()
```

Putting the code into the configureChart method gives:

```auto
AttributeError: 'NoneType' object has no attribute 'setTickUnit'
```

…as if getRangeAxis returned nothing.

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [October 29, 2018, 5:24pm UTC](https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342/9 "2018-10-29T17:24:38Z")

</div>

You didn’t get the JFreeChart object yet. You have to either drill down like this or use the chart variable as Phil suggested

```auto
trend.getComponent(0).getComponent(0).getChart().getXYPlot().getRangeAxis().setTickUnit(NumberTickUnit(5.0))

```

---

<div class="post-metadata">

**Author:** ![ASF](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ASF](https://forum.inductiveautomation.com/u/ASF)\
**Post date:** [October 29, 2018, 10:03pm UTC](https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342/10 "2018-10-29T22:03:14Z")

</div>

Using the chart variable in the configureChart method, I have this code:

`from org.jfree.chart.axis import NumberTickUnit
chart.getXYPlot().getRangeAxis().setTickUnit(NumberTickUnit(5))`  
I have broken it down piece by piece…

`plot = chart.getXYPlot()
print plot` prints org.jfree.chart.plot.CombinedDomainXYPlot@…

` axis = plot.getRangeAxis()
print axis` prints None.

I called getRangeAxisCount and it returns 1, so it knows that there is a range axis. I’ve tried calling getRangeAxis(0), getRangeAxis(1) and getRangeAxis(2), in case it’s as simple as needing to directly specify the range axis, but each time it returned none.

I also tried your code outside the configureChart method:

```auto
trend.getComponent(0).getComponent(0).getChart().getXYPlot().getRangeAxis().setTickUnit(NumberTickUnit(5))
```

`from org.jfree.chart.axis import NumberTickUnit
chart = trend.getComponent(0).getComponent(0)
print chart` prints ‘org.jfree.chart.JFreeChart@…’  
Then adding on `plot = chart.getXYPlot()` throws the error: `org.jfree.chart.plot.PiePlot cannot be cast to org.jfree.chart.plot.XYPlot`  
which has me stumped, because this is an Easy Chart, not a Pie Chart.

---

<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:** [October 29, 2018, 10:12pm UTC](https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342/11 "2018-10-29T22:12:11Z")

</div>

The XYPlot you’re looking for is probably one of the [subplots](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/CombinedDomainXYPlot.html#getSubplots--) of the [`CombinedDomainXYPlot`](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/CombinedDomainXYPlot.html). Get the list, iterate through it, check whether one is the XYPlot you’re looking for.

---

<div class="post-metadata">

**Author:** ![ASF](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ASF](https://forum.inductiveautomation.com/u/ASF)\
**Post date:** [October 29, 2018, 11:45pm UTC](https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342/12 "2018-10-29T23:45:20Z")

</div>

I ended up creating a new easy chart object, and trying the code out in there, just to see if there was something funny going on with the existing Easy Chart. Either of the methods above worked without any further modification, so it’s obviously something to do with the configuration of my existing Easy Chart.

Ultimately I’m actually trying to modify the X axis ticks, not the Y axis ticks. I just wanted to take it one step at a time and get the Y axis working off the example, then move onto the X axis. Having made the Y axis work on a new easy chart, I modified it to get the X axis working on the new chart. Then I transposed the code across to the old easy chart, and it works there too. Y axis still doesn’t, but as I say, the Y axis ticks are managed a different way so all is under control.

Thanks for persevering with me!

---

<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:** [October 30, 2018, 12:41am UTC](https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342/13 "2018-10-30T00:41:17Z")

</div>

> [@ASF](#):
>
> Then I transposed the code across to the old easy chart, and it works there too. Y axis still doesn't, but as I say, the Y axis ticks are managed a different way so all is under control.

I'm going to guess that your original chart has subplots, as alluded to by Paul. When true, you have to get the actual range axes from the subplots.

---

<div class="post-metadata">

**Author:** ![ASF](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ASF](https://forum.inductiveautomation.com/u/ASF)\
**Post date:** [October 30, 2018, 12:48am UTC](https://forum.inductiveautomation.com/t/xy-plot-tick-units/16342/14 "2018-10-30T00:48:36Z")

</div>

Spot on, I do have multiple subplots. That explains that!
