JFreeChart line not displayed correctly

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
KK12
Posts: 1
Joined: Tue Jan 23, 2018 11:13 am
antibot: No, of course not.

JFreeChart line not displayed correctly

Post by KK12 » Tue Jan 23, 2018 11:20 am

Hello,
I am creating a chart and notice that the points are not connected in the right order.
In the code mentioned below, the point (3,6) with point (4,5) would actually have to pass
through connected to a line, instead it is connected to point (4,3).
Does anyone have an idea how to solve this?

Thanks in advance

Code: Select all

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.DefaultXYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.chart.renderer.xy.*;



public class TestChart {

    public static void main(String[] args) {
       
       XYSeries series1 = new XYSeries("Punkte1");      
        series1.add(4,3);
        series1.add(4,4);
        series1.add(4,5);
        series1.add(3,6);

        XYSeriesCollection dataset2 = new XYSeriesCollection();
        dataset2.addSeries(series1);
        XYLineAndShapeRenderer dot = new XYLineAndShapeRenderer();
        NumberAxis xyx = new NumberAxis("x");
        NumberAxis yax = new NumberAxis("y");
       
        XYPlot plot = new XYPlot(dataset2, xyx, yax, dot);      
        JFreeChart chart2 = new JFreeChart(plot);
        ApplicationFrame punkteframe = new ApplicationFrame("Punkte");
        ChartPanel chartPanel2 = new ChartPanel(chart2);
        punkteframe.setContentPane(chartPanel2);
        punkteframe.pack();
        punkteframe.setVisible(true);

    }

}

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: JFreeChart line not displayed correctly

Post by paradoxoff » Tue Jan 23, 2018 3:23 pm

Use the XYSeries constructor that accepts a boolean parameter and set that to "false".

Locked