XY plot tick units

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:


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:


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?

Instead of:


from org.jfree.chart.axis import NumberTickUnit
1 Like

Thank you.

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

Probably setAutoTickUnitSelection(True) or similar function on the ValueAxis.

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

trend = event.source.parent.getComponent('Easy Chart')
from org.jfree.chart.axis import NumberTickUnit

AttributeError: ‘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.

The EasyChart is not a ChartPanel 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.

trend = event.source.parent.getComponent('Easy Chart')
from org.jfree.chart.axis import NumberTickUnit

gives the error:

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

Putting the code into the configureChart method gives:

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

…as if getRangeAxis returned nothing.

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


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:


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.

The XYPlot you’re looking for is probably one of the subplots of the CombinedDomainXYPlot. Get the list, iterate through it, check whether one is the XYPlot you’re looking for.

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!

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.


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