?
Solved

How to show a XY Chart using JFreeChart ??

Posted on 2003-11-06
2
Medium Priority
?
733 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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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…
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

765 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