XYSeries and XYSeriesCollection

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Allyson Gwin

XYSeries and XYSeriesCollection

Post by Allyson Gwin » Thu Mar 13, 2003 6:46 pm

I know I have asked this question in the past and have gotten some answers, but I am still stumped as to how to change the XYSeries code so that it does not sort. Someone mentioned this:

Look at the line 139 of XYSeries.java.
It returns the index where the "pair" object is going to be inserted in the already sorted "data" list.

// make the change (if it's not a duplicate time period)...
int index = Collections.binarySearch(data, pair);

but I don't see how this sorts that data. I really need to change this to get my graphs to look the way the user wants them to look.

I think I could figure out how to make a jar file and compile this after it is changed, but then how can I make sure that the XYSeries.class is not used from the jfreechart*.jar? I think I need other stuff from the jfreechart*.jar so I can't just not use it. Any ideas?

Thanks.

Allyson

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: XYSeries and XYSeriesCollection

Post by david.gilbert » Fri Mar 14, 2003 1:10 pm

Allyson Gwin wrote:// make the change (if it's not a duplicate time period)...
int index = Collections.binarySearch(data, pair);

but I don't see how this sorts that data. I really need to change this to get my graphs to look the way the user wants them to look.
The binarySearch method either returns the index of the item, or a negative value that indicates the position that the item should take in order to maintain the sort order (refer to the JDK Javadocs for details).

If you don't want sorting, then you could just ignore the index and add the item to the end of the list. You might want to scan the rest of the code to see if anything else relies on the sort order.

Regards,

Dave Gilbert

ajgwin
Posts: 18
Joined: Mon Mar 17, 2003 4:53 pm

Re: XYSeries and XYSeriesCollection

Post by ajgwin » Mon Mar 17, 2003 5:00 pm

I commented out the code below:

public void add(XYDataPair pair) throws SeriesException {

// check arguments...
if (pair == null) {
throw new IllegalArgumentException("XYSeries.add(...): null item not allowed.");
}

// make the change (if it's not a duplicate x-value)...
// int index = Collections.binarySearch(data, pair); commented out by ajg on mar 17, 2003
// if (index < 0) { commented out by ajg on mar 17, 2003
// data.add(-index - 1, pair); commented out by ajg on mar 17, 2003
// fireSeriesChanged(); commented out by ajg on mar 17, 2003
// } commented out by ajg on mar 17, 2003
// else { commented out by ajg on mar 17, 2003
if (allowDuplicateXValues == true) {
data.add(index, pair);
fireSeriesChanged();
}
else {
throw new SeriesException("XYSeries.add(...): x-value already exists.");
}
// } commente out by ajg on mar 17, 2003

}

I think this should work to remove the index. Now, I should compile it and put it in it's own jar file? I still need to use jfreechart-0.9.4.jar for other things so how do I get the program to ignore the XYSeries.class that is in the jfreechart-0.9.4.jar? I hope I don't need to recompile everything else and put it in another jar file. Thanks.

Allyson

ajgwin
Posts: 18
Joined: Mon Mar 17, 2003 4:53 pm

Re: XYSeries and XYSeriesCollection

Post by ajgwin » Mon Mar 17, 2003 5:49 pm

I recompiled XYSeries and now I have XYSeries.class. How can I use this instead of the XYSeries.class that is in the jfreechart-0.9.4.jar? Thanks.

Allyson

Irv Thomae

Re: XYSeries and XYSeriesCollection

Post by Irv Thomae » Mon Mar 17, 2003 9:59 pm

ajgwin wrote:I recompiled XYSeries and now I have XYSeries.class. How can I use this instead of the XYSeries.class that is in the jfreechart-0.9.4.jar? Thanks.

Allyson
It seems as if I often find myself experimenting with small changes to JFreeChart code. There are two things I do:
(1) always compile with javac's "-d classes" option - keeps my source directory from being cluttered up with classfiles, instead they go into a subdirectory below my source path called "classes". If you don't remove the "package" statement from "your" version of XYSseries, this will put the classfile in
classes/com/jrefinery/data/XYseries.class

(2) Arrange my CLASSPATH so that "my" paths are checked before the JFreeChart jar-files:
set CLASSPATH=./:./classes:jfreechart-0/9/6.jar:<etc...>:$CLASSPATH

In this way, "my" version(s) are found before - and instead of - those in the JFreeChart jar's.

Irv Thomae

Re: XYSeries and XYSeriesCollection

Post by Irv Thomae » Mon Mar 17, 2003 9:59 pm

[quote="ajgwin"]I recompiled XYSeries and now I have XYSeries.class. How can I use this instead of the XYSeries.class that is in the jfreechart-0.9.4.jar? Thanks.

Allyson[/quote]

It seems as if I often find myself experimenting with small changes to JFreeChart code. There are two things I do:
(1) always compile with javac's "-d classes" option - keeps my source directory from being cluttered up with classfiles, instead they go into a subdirectory below my source path called "classes". If you don't remove the "package" statement from "your" version of XYSseries, this will put the classfile in
classes/com/jrefinery/data/XYseries.class

(2) Arrange my CLASSPATH so that "my" paths are checked before the JFreeChart jar-files:
set CLASSPATH=./:./classes:jfreechart-0/9/6.jar:<etc...>:$CLASSPATH

In this way, "my" version(s) are found before - and instead of - those in the JFreeChart jar's.

Irv Thomae

XYSeries and XYSeriesCollection

Post by Irv Thomae » Mon Mar 17, 2003 10:00 pm

Alison:

It seems as if I often find myself experimenting with small changes to JFreeChart code. There are two things I do:
(1) always compile with javac's "-d classes" option - keeps my source directory from being cluttered up with classfiles, instead they go into a subdirectory below my source path called "classes". If you don't remove the "package" statement from "your" version of XYSseries, this will put the classfile in
classes/com/jrefinery/data/XYseries.class

(2) Arrange my CLASSPATH so that "my" paths are checked before the JFreeChart jar-files:
set CLASSPATH=./:./classes:jfreechart-0/9/6.jar:<etc...>:$CLASSPATH

In this way, "my" version(s) are found before - and instead of - those in the JFreeChart jar's.

ajgwin
Posts: 18
Joined: Mon Mar 17, 2003 4:53 pm

Re: XYSeries and XYSeriesCollection

Post by ajgwin » Mon Mar 17, 2003 10:09 pm

Thank you, thank you, thank you. I finally got it to work. I want to thank everyone for all their help. It all helped and I now have the sorting removed. Phew! Thanks again.

Allyson

Locked