Dynamic RangeAxis in Reports

Hello! I’m currently working with the Timeseries Charts script in the reporting module. I already have the code for dynamic charts, handling the legend dynamically, and adding as many RangeAxis as needed.

My problem is that I don’t know how to specify the RangeAxis I want a pen to use. Could someone help me? :confounded: :confounded: :confounded:

Thanks in advance.

1 Like

The XYPlot class you must be using to manipulate the pens expects there to be a 1:1:1:1 relationship between datasets, domain axes, range axes, and renderers.

All of these must be specified at index zero, and these become the defaults for any datasets that don't have a specific assignment for one of the other items.

Therefore, place pens in the dataset that has the index corresponding to the range axis you've assigned to the XYPlot.

1 Like

OK thanks!

But another question arises: what would be the class that defines the concept "pen"?

Series within each dataset. All of the series in a dataset share domain axis, range axis, and renderer. Beware: JFreeChart "datasets" are not the same class as Ignition's own "datasets".

1 Like

Hello once again. I've already made some progress but I haven't quite made it :worried: I need to know how to remove series from a dataset. While reviewing the API, I noticed that there’s a removeSeries(Comparable seriesKey) method for DefaultXYDataset, but it’s not working for me. Here’s my test:

from org.jfree.data.xy import DefaultXYDataset

plot = chart.getPlot()
dataset = plot.getDataset()
key = dataset.getSeriesKey(0)
dataset.removeSeries(key)

Help please :pleading_face:

Why?

Just construct however many datasets you need (DefaultXYDataset I suspect) for all of the combinations of axes for your data, assigning them to the plot, starting with subscript zero.

https://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/XYPlot.html

1 Like

I understand what you're trying to tell me, but when I’ve tried to do that, I always get an error. The method I used to do this was the addSeries(Comparable seriesKey, double[][] data) of the DefaultXYDataset() class.
Isn’t that the right function? Do you know how this is done?

This made me think that perhaps it was easier to remove series than to add them. As the graph is dynamic I have to configure at the beginning the maximum number of PENs that I can use. Then I will always have in the index 0 dataset the configuration of all the series. I can clone that dataset and remove from there the series that I don't need. Do you think I should keep trying to figure out how to add series to a data set?

I really appreciate your help and forgive me for so much trouble :sweat:

Series have to be sequential, I believe.

You have the right method. To submit a two-dimensional array of double, you may need to use jython's jarray module.

I just tried this small test, and it doesn’t work:

from org.jfree.data.xy import DefaultXYDataset
newDataset = DefaultXYDataset()
myNumbers = [[1], [5]]
newDataset.addSeries(key, myNumbers)

myNumbers is a list of lists, not a java array of arrays of double. I don't see where you are defining key.

How can I define a jarray? I'm know nothing about Python or Java so I'm really struggling with all this.

And 'key' was defined before, sorry:

plot = chart.getPlot()
dataset = plot.getDataset()
key = dataset.getSeriesKey(0)

from org.jfree.data.xy import DefaultXYDataset
newDataset = DefaultXYDataset()
myNumbers = [[1], [5]]
newDataset.addSeries(key, myNumbers)

import jarray

See Java Arrays in Jython

You can't use the key of an existing series for your new series. Give it a unique name.

Ohhhh! I'll give it a try. I hope I don't have to bother you again :sweat_smile: :sweat_smile: