Results 1 to 10 of 10
  1. #1
    getName() is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default 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.

    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));
                ...}
    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.

    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 &bull; View topic - XYLinePlot curve jumps horizontally, too. No one replied so far. Maybe someone can help me here.

    Thanks in advance.

    Benjamin

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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! :)

  3. #3
    getName() is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    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?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Can you create a text file of the data and then upload it either here or somewhere? I'm still curious about it.

  5. #5
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    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);

  6. #6
    getName() is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    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.
    Attached Files Attached Files
    Last edited by getName(); 09-07-2010 at 10:58 PM.

  7. #7
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    It might be helpful to put a println in here

    Java Code:
    for (int i=0; i<pData.length-2; i++){
                        set.add(pData[i][col[0]],pData[i][col[1]]*multiplier);
                    }
    To dump out "pData[i][col[0]]" and "pData[i][col[1]]*multiplier" to make sure they're what you think they are.

  8. #8
    getName() is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    That's what I did.
    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);
    Copy and paste in Origin. Result: data look nice.

  9. #9
    getName() is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    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.

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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

  1. I want the output to be apper HORIZONTALLY
    By o0oNorao0o in forum New To Java
    Replies: 8
    Last Post: 01-21-2010, 01:24 PM
  2. How to duplicat drawOval horizontally?
    By ntagrafix in forum AWT / Swing
    Replies: 1
    Last Post: 12-03-2009, 10:37 PM
  3. Scrollbar jumps back after setting thumb
    By swtpete in forum SWT / JFace
    Replies: 0
    Last Post: 11-02-2009, 01:42 PM
  4. How to draw a Smooth Curve using jfreechart
    By Manfizy in forum New To Java
    Replies: 1
    Last Post: 07-07-2009, 10:01 AM
  5. Java Learning Curve
    By mwildam in forum New To Java
    Replies: 13
    Last Post: 10-17-2008, 12:09 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •