8 Replies Latest reply: Feb 15, 2013 10:23 AM by 990104 RSS

    JFreeChart SplineRenderer code problem

    990104
      I tried to write simple JFreeChart SplineRenderer code, but it don't work. Can sameone tell whats wrong with it? Netbeans say that error is in XYPlot plot = new XYPlot(dataset, xax, yax, spline); line. I'm newbie in java programming...

      package kubas;

      import org.jfree.chart.*;
      import org.jfree.chart.axis.*;
      import org.jfree.chart.plot.*;
      import org.jfree.chart.renderer.xy.XYSplineRenderer;
      import org.jfree.data.xy.*;
      import org.jfree.ui.ApplicationFrame;

      public class spausdink {

      public static void main(String[] args) {

      XYSeries series = new XYSeries("XY grafikas");
      series.add(1, 2);
      series.add(2, 4);
      series.add(3, 8);
      series.add(4, 16);
      series.add(5, 32);
      series.add(6, 64);
      series.add(7, 128);
      series.add(8, 256);
      series.add(9, 512);
      series.add(10, 1024);

      XYSeriesCollection dataset = new XYSeriesCollection();
      dataset.addSeries(series);



      ApplicationFrame frame = new ApplicationFrame("Mano grafikas");
      XYSplineRenderer spline = new XYSplineRenderer();

      NumberAxis xax = new NumberAxis("x");
      NumberAxis yax = new NumberAxis("y");

      XYPlot plot = new XYPlot(dataset, xax, yax, spline);

      JFreeChart chart = new JFreeChart(plot);

      ChartPanel chartPanel = new ChartPanel(chart);
      frame.setContentPane(chartPanel);
      frame.pack();
      frame.setVisible(true);


      }

      }

      Edited by: 987101 on 2013.2.8 17.48

      Edited by: 987101 on 2013.2.8 17.53
        • 1. Re: JFreeChart SplineRenderer code problem
          990104
          I understand that it is stupid question for programmers, but I really need help with this thing. I really appreciate if someone would help:)
          • 2. Re: JFreeChart SplineRenderer code problem
            sabre150
            987101 wrote:
            I understand that it is stupid question for programmers, but I really need help with this thing. I really appreciate if someone would help:)
            Maybe someone could help if they knew what the error message is! For my part, the code works without any problem so I can't possibly help!
            • 3. Re: JFreeChart SplineRenderer code problem
              990104
              Here is error mesagges [http://i.stack.imgur.com/D6Wbl.jpg] , on Netbeans I tried two codes and both don't work. Maybe it's software problem? I added jfreechart 1.0.14 libraries.

              Edited by: 987101 on 2013.2.10 05.32

              Edited by: 987101 on 2013.2.10 05.33
              • 4. Re: JFreeChart SplineRenderer code problem
                sabre150
                987101 wrote:
                Here is error mesagges [http://i.stack.imgur.com/D6Wbl.jpg] , on Netbeans I tried two codes and both don't work. Maybe it's software problem? I added jfreechart 1.0.14 libraries.
                I too am using JFreeChart 1.0.14 within Netbeans and both those two approaches work for me without errors! Are you sure you are using 1.0.14 ?
                • 5. Re: JFreeChart SplineRenderer code problem
                  990104
                  I had already solved the problem. Created new project and now it works! Thanks.
                  • 6. Re: JFreeChart SplineRenderer code problem
                    990104
                    I have another problem. I want to make graphs without points, but only higher graph is without points, what I should change in code to hide points in both graphs?

                    import java.awt.Color;
                    import org.jfree.chart.*;
                    import org.jfree.chart.axis.*;
                    import org.jfree.chart.plot.*;
                    import org.jfree.chart.renderer.xy.XYSplineRenderer;
                    import org.jfree.data.xy.*;
                    import org.jfree.ui.ApplicationFrame;

                    public class code {

                    public static void main(String[] args) {
                    XYSeries series1 = new XYSeries("XY graph first");
                    series1.add (0, 0);
                    series1.add (1, 20);
                    series1.add (2, 70);
                    series1.add (3, 140);
                    series1.add (4, 210);
                    series1.add (5, 280);
                    series1.add (6, 360);
                    series1.add (7, 600);
                    series1.add (8, 800);
                    series1.add (9, 1000);
                    series1.add (10, 1200);

                    XYSeries series2 = new XYSeries("XY graph second");
                    series2.add(0, 0);
                    series2.add(1, 2);
                    series2.add(2, 4);
                    series2.add(3, 8);
                    series2.add(4, 16);
                    series2.add(5, 32);
                    series2.add(6, 64);
                    series2.add(7, 128);
                    series2.add(8, 256);
                    series2.add(9, 512);
                    series2.add(10, 1024);

                    XYSeriesCollection dataset = new XYSeriesCollection();
                    dataset.addSeries(series1);
                    dataset.addSeries(series2);

                    ApplicationFrame frame = new ApplicationFrame("Graph");

                    NumberAxis xax = new NumberAxis("X axis");
                    NumberAxis yax = new NumberAxis("Y axis");
                    XYSplineRenderer spline = new XYSplineRenderer();
                    spline.setPrecision(10);

                    XYPlot xyplot = new XYPlot(dataset, xax, yax, spline);

                    //Design
                    spline.setSeriesShapesVisible(0, false);
                    xyplot.setBackgroundPaint( Color.pink );
                    xyplot.setDomainGridlinePaint( Color.WHITE );
                    xyplot.setRangeGridlinePaint( Color.WHITE );

                    JFreeChart chart = new JFreeChart(xyplot);

                    ChartPanel chartPanel = new ChartPanel(chart);
                    frame.setContentPane(chartPanel);
                    frame.pack();
                    frame.setVisible(true);


                    }

                    }

                    Edited by: 987101 on 2013.2.14 17.05
                    • 7. Re: JFreeChart SplineRenderer code problem
                      sabre150
                      I find it difficult to find any enthusiasm for helping you further! Just go through your code and the simple way to do this becomes pretty obvious and if you bothered to read the Javadoc for the renderer you would find an even better way.
                      • 8. Re: JFreeChart SplineRenderer code problem
                        990104
                        Find out how to do that. Just need to copy line and change numer in brackets, and it works for both graphs;)

                        spline.setSeriesShapesVisible(0, false);
                        spline.setSeriesShapesVisible(1, false);

                        Thanks anyway.

                        Edited by: 987101 on 2013.2.15 08.16