Meaningless Drivel is fun!
The moose likes Other Open Source Projects and the fly likes Any1 know drawin pie chart using jfreechart Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Any1 know drawin pie chart using jfreechart" Watch "Any1 know drawin pie chart using jfreechart" New topic

Any1 know drawin pie chart using jfreechart


Joined: Apr 12, 2004
Posts: 2
does anyone know how to use jfreechart n draw pie chart?? wat my fren did is diff from what i read in the internet resources i found. i am using MySql as my backbone database, using servlets to view it in web browser.i dun understand wat each line means onli some i noe.
*****************my fren codes(**********************
Class Name: Charts
Functionality: Creates Charts
import java.awt.*;
import java.awt.geom.*;
import java.awt.Paint;
import org.jfree.chart.*;
import org.jfree.chart.axis.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.labels.*;
import org.jfree.chart.renderer.*;
import org.jfree.util.*;
import org.jfree.chart.ChartFactory;

public class Charts
//initialize variable
JFreeChart chart = null;
//class constructor
public Charts()
//called by convert.class to create chart
public void createChart(String chartName, String items[], double percentage[])
//creates dataset first
PieDataset dataset = createDataset(items, percentage);
//creates 3D effect pie-chart
chart = ChartFactory.createPieChart3D(chartName, dataset, true, false, false);
Parameters for ChartFactory.createPieChart3D:
title - the chart title.
data - the dataset for the chart.
legend - a flag specifying whether or not a legend is required.
tooltips - configure chart to generate tool tips?
urls - configure chart to generate URLs?
//set background color of chart - default is yellow but i want to set it to white
//adjust pie-chart settings
Pie3DPlot pie3dplot = (Pie3DPlot)chart.getPlot();
pie3dplot.setNoDataMessage("No data to display");
//Types of labels
pie3dplot.setNoDataMessage("No data available");
//creates pie chart data based on items and percentage array
public PieDataset createDataset(String items[], double percentage[])
//creates default piechart dataset
DefaultPieDataset dataset = new DefaultPieDataset();
int iMaxItems = items.length;
if (percentage.length < iMaxItems)
iMaxItems = percentage.length;
//populate pie chart values
for (int i = 0 ; i < iMaxItems ; i++)
//sets values of pie chart
dataset.setValue(items[i], percentage[i]);
return dataset;
//draws piechart
public void draw(Graphics2D g, Rectangle2D r)
chart.draw(g, r);
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

Mr Rocks,
Welcome to JavaRanch!
We don't have too many rules around here, but we do have our naming policy which requires that your display name be a real name, not an obvious fake. Please go here and update yours, pronto! Thanks, pardner.

[Jess in Action][AskingGoodQuestions]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Other Open Source Projects forum...

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Any1 know drawin pie chart using jfreechart
jQuery in Action, 3rd edition