?
Solved

How to create a Graph Charts using JFreeChart

Posted on 2003-03-30
6
Medium Priority
?
1,438 Views
Last Modified: 2008-02-01
Hi all,
     
      I am trying to create charts by using JFreeChart-0.9.4 in my application.  As its mentioned in the http://www.javaworld.com/javaworld/jw-12-2002/jw-1227-opensourceprofile.html.  I added two jar files i.e

"To compile and run the code, you must have two jar files from the JFreeChart distribution, jfreechart-0.9.4.jar and jcommon-0.7.1.jar, in your classpath"

for example:  For Pie Chart, following code must be written.

DefaultPieDataset pieDataset = new DefaultPieDataset();
pieDataset.setValue("JavaWorld", new Integer(75));
pieDataset.setValue("Other", new Integer(25));

JFreeChart chart = ChartFactory.createPieChart
                     ("Sample Pie Chart",   // Title
                      pieDataset,           // Dataset
                      true                  // Show legend  
                     );


I ADDED JAR FILES IN MY CLASSPATH. BUT STILL I AM GETTING AN ERROR WHEN I AM COMPILING THE PROGRAM.
THE ERRORS ARE "Unresolved Class DefaultPieDataset"  and so on all the classes that are used in the above code.

 Pls Help me out. I am really oblized to you if u can guide me step by step that has to be done.
 
  Thank you,

   Nagesh.



0
Comment
Question by:nages_21
[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
  • 3
6 Comments
 
LVL 3

Accepted Solution

by:
msterjev earned 500 total points
ID: 8236836
Did you import into your code the correct package?
0
 
LVL 3

Expert Comment

by:msterjev
ID: 8236851
import com.jrefinery.data.DefaultPieDataset;
0
 
LVL 3

Expert Comment

by:msterjev
ID: 8236859
package com.jrefinery.chart.demo;

import java.awt.Color;
import com.jrefinery.data.DefaultPieDataset;
import com.jrefinery.ui.ApplicationFrame;
import com.jrefinery.chart.JFreeChart;
import com.jrefinery.chart.ChartFactory;
import com.jrefinery.chart.ChartPanel;
import com.jrefinery.chart.Pie3DPlot;

/**
 * A simple demonstration application showing how to create a pie chart using data from a
 * DefaultPieDataset.
 */
public class Pie3DChartDemo1 extends ApplicationFrame {

    /**
     * Default constructor.
     */
    public Pie3DChartDemo1(String title) {

        super(title);

        // create a dataset...
        DefaultPieDataset data = new DefaultPieDataset();
        data.setValue("Java", new Double(43.2));
        data.setValue("Visual Basic", new Double(10.0));
        data.setValue("C/C++", new Double(17.5));
        data.setValue("PHP", new Double(32.5));
        data.setValue("Perl", new Double(12.5));

        // create the chart...
        JFreeChart chart = ChartFactory.createPie3DChart("Pie Chart Demo 1",  // chart title
                                                         data,                // data
                                                         true                 // include legend
                                                         );

        // set the background color for the chart...
        chart.setBackgroundPaint(Color.yellow);
        Pie3DPlot plot = (Pie3DPlot)chart.getPlot();
        plot.setStartAngle(270);
        plot.setDirection(Pie3DPlot.CLOCKWISE);
        plot.setForegroundAlpha(0.5f);
        // add the chart to a panel...
        ChartPanel chartPanel = new ChartPanel(chart);
        this.setContentPane(chartPanel);

    }

    /**
     * Starting point for the demonstration application.
     */
    public static void main(String[] args) {

        Pie3DChartDemo1 demo = new Pie3DChartDemo1("Pie Chart Demo 1");
        demo.pack();
        demo.setVisible(true);

    }

}
0
 

Expert Comment

by:CleanupPing
ID: 9058378
nages_21:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9735849
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept msterjev's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 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