Solved

How to show a XY Chart using JFreeChart ??

Posted on 2003-11-06
2
721 Views
Last Modified: 2008-03-17
Hi guys,

   I got the following code :

import java.awt.*;
import java.awt.event.*;
import java.io.PrintStream;
import java.util.ResourceBundle;
import java.util.Vector;
import javax.swing.*;

import org.jfree.chart.JFreeChart;
import org.jfree.data.XYSeries;
import org.jfree.data.XYSeriesCollection;
import org.jfree.data.XYDataset;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.plot.PlotOrientation;

public class JChartXY implements ActionListener, WindowListener
{

    public static void main(String[] args) {
      
      XYSeries series = new XYSeries("Average Size");
      series.add(20.0, 10.0);
      series.add(40.0, 20.0);
      series.add(70.0, 50.0);
      XYDataset xyDataset = new XYSeriesCollection(series);
      
      JFreeChart chart = ChartFactory.createXYAreaChart
                           ("Sample XY Chart",  // Title
                            "Height",           // X-Axis label
                            "Weight",           // Y-Axis label
                            xyDataset,          // Dataset
                            PlotOrientation.HORIZONTAL,
                            true,                // Show legend
                            false,
                            false
                           );
                     }
}

it compiled successfully but nothing show up ! So how to make the XY Chart appear ? Thanks !
0
Comment
Question by:northborneo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:northborneo
ID: 9699657
guys .... pls help. ...pls ..pls
0
 
LVL 15

Accepted Solution

by:
jimmack earned 125 total points
ID: 9700052
It looks like you've created the chart OK, but you haven't displayed it.  Have a look in the documentation (there should be some examples).  Do you need to add the "chart" object to a JFrame or similar?

OK.  Got it.

Add the following:

import org.jfree.chart.ChartPanel;

For testing, I changed the class definition to:

public class JChartXY  // ie. removed the implements

Then added the following code at the end of your main method:

        JFrame mainFrame = new JFrame("Chart test");
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
        ChartPanel mainPanel = new ChartPanel(chart);
       
        mainFrame.getContentPane().add(mainPanel);
       
        mainFrame.setSize(new Dimension(600, 400));
        mainFrame.show();
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
V.simple question about Android packages and libraries 1 38
hibernate jars 4 61
ejb stateless example 2 44
Eclipse Help Java EE 5,6,7 Documentation, why not Java EE 8 8 46
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question