I am using JFreeChart to create a histogram of an image in java swing. To create it, I iterate over all the pixels to get all the colors. Depending on the size and depth of the bit, some time is required.
As soon as I have all the data, I put it in the XYSeriesCollection variable. To be able to show and hide some series, I keep a copy of this variable.
My problem is if I do it like this:
final XYSeriesCollection data = createHistogram(); final XYSeriesCollection dataCopy = createHistogram();
It works without any problems, but it is inefficient as I have to iterate over all the pixels, and this takes some time.
If I just copy it like this:
final XYSeriesCollection data = createHistogram(); final XYSeriesCollection dataCopy = data;
When I execute the code, I get this exception:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Series index out of bounds at org.jfree.data.xy.XYSeriesCollection.getSeries(XYSeriesCollection.java:263)
I think this is because when I delete a series from data, some of them are also deleted from dataCopy, but should they not be completely different? I just work with these methods:
data.removeAllseries(); data.addSeries(dataCopy.getSeries(index));
For example, if I create:
int x = 5; int y = x; x=0; System.out.println(y)
The output should be 5, and it doesn't matter what I did with x. What am I doing or suppose this is wrong?
Thanks.