Results 1 to 10 of 10
- 09-05-2010, 09:48 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 11
- Rep Power
- 0
JFreeChart XYLinePlot curve jumps horizontally
Hi,
I am using an XYPlot to visualize some measurement data. I am creating a dataset (see below) passing an double[][]-Array which contains the data in columns (i.e. column 1: current; column 2: voltage, etc.).
Java Code:private XYDataset createDataset(int[] col,double[][] pData, int multiplier) { String setName = "set_"+String.valueOf(datasetNumber); XYSeries set = new XYSeries(setName); for (int i=0; i<pData.length-2; i++){ set.add(pData[i][col[0]],pData[i][col[1]]*multiplier); } return new XYSeriesCollection(set); }
The relevant code to create the plot is shown below.
Now if the curves are smooth, everything is fine. But as soon as the curve starts jumping from value to value, the Plot appears to draw lines horizontally. Whereas MATLAB or Origin plot the curves properly, XYLinePlot seems to have a problem with heavy jumps in the dataset. Below you find links to some plots.Java Code:private JFreeChart createChart() { JFreeChart chart = ChartFactory.createXYLineChart(titleText,"Power [mW]","Current [mA]",null,PlotOrientation.HORIZONTAL, false, true, false); plot = (XYPlot) chart.getPlot(); plot.setDataset(this.datasetNumber,createDataset(col,retrieveData(pFile),1000)); plot.setRenderer(this.datasetNumber, new XYLineAndShapeRenderer(true, false)); ...}
JFreeChart
Origin
I don't see why this happens. Does anyone know a solution or see the error I've made? If I do not draw lines in between data points it looks fine.
By the way, I have posted a thread like this in www.jfree.org • View topic - XYLinePlot curve jumps horizontally, too. No one replied so far. Maybe someone can help me here.
Thanks in advance.
Benjamin
-
I have to wonder, is the x data (which I gather is held in pData[i][col[0]]) monotonically increasing or does it jump around? If it jumps around, would it help to sort the data first so that it is monotonically increasing before plotting it?
Note that I know nothing about JFreeChart.
Edit: thanks for the cross-post link! It is really appreciated! :)
- 09-05-2010, 11:09 PM #3
Member
- Join Date
- Jun 2010
- Posts
- 11
- Rep Power
- 0
No. The x-data is monotonically increasing. I've checked that already.
It is really annoying, since I don't find a solution. This happens only to a few datasets. XY-Plot in LabView with the same data looks OK.
Another idea?
-
Can you create a text file of the data and then upload it either here or somewhere? I'm still curious about it.
- 09-07-2010, 05:31 AM #5
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
My guess...and this is just a guess... is that the following line is not doing what you expect:
Java Code:set.add(pData[i][col[0]],pData[i][col[1]]*multiplier);
- 09-07-2010, 09:07 PM #6
Member
- Join Date
- Jun 2010
- Posts
- 11
- Rep Power
- 0
OK, sorry it took so long. I've attached a textfile with data where this effect occurs.
@toadaly: what, if your guess is right? Another guess? I'd appreciate it.
I've added a System.out.println, copied and pasted the data into Origin - and they looked just fine.
If I flip x and y the heavy jumps remain horizontal. I must be doing something really wrong.Last edited by getName(); 09-07-2010 at 09:58 PM.
- 09-07-2010, 10:23 PM #7
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
It might be helpful to put a println in here
To dump out "pData[i][col[0]]" and "pData[i][col[1]]*multiplier" to make sure they're what you think they are.Java Code:for (int i=0; i<pData.length-2; i++){ set.add(pData[i][col[0]],pData[i][col[1]]*multiplier); }
- 09-07-2010, 10:29 PM #8
Member
- Join Date
- Jun 2010
- Posts
- 11
- Rep Power
- 0
That's what I did.
Copy and paste in Origin. Result: data look nice.Java Code:set.add(pData[i][col[0]],pData[i][col[1]]*multiplier); System.out.println(pData[i][col[0]] + " " + pData[i][col[1]]*multiplier);
- 09-08-2010, 10:10 PM #9
Member
- Join Date
- Jun 2010
- Posts
- 11
- Rep Power
- 0
So, after having slept properly, I have found the solution. So easy. How embarrassing!
I did probably everything wrong that can be done wrong:
1. exchanged x and y-axis in plot
2. set plotOrientation.HORIZONTAL
3. added the data to the dataset again add (y,x) instead of (x,y)
Well, all of it together made normal curves look normal. But jumps were, of course, horizontal.
Now I got everything together. Thank you guys anyway for your advice and time.
-
Congrats on solving it yourself, and many thanks for getting back with us on the results of your efforts. I know that you had several of us scratching our heads over this one, but all's well that ends well! :)
Similar Threads
-
I want the output to be apper HORIZONTALLY
By o0oNorao0o in forum New To JavaReplies: 8Last Post: 01-21-2010, 12:24 PM -
How to duplicat drawOval horizontally?
By ntagrafix in forum AWT / SwingReplies: 1Last Post: 12-03-2009, 09:37 PM -
Scrollbar jumps back after setting thumb
By swtpete in forum SWT / JFaceReplies: 0Last Post: 11-02-2009, 12:42 PM -
How to draw a Smooth Curve using jfreechart
By Manfizy in forum New To JavaReplies: 1Last Post: 07-07-2009, 09:01 AM -
Java Learning Curve
By mwildam in forum New To JavaReplies: 13Last Post: 10-17-2008, 11:09 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks