aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
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
Author

Any1 know drawin pie chart using jfreechart

Mingyu
Greenhorn

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(Charts.java**********************
/***************************************************************
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.data.*;
import org.jfree.data.time.*;
import org.jfree.util.*;
import org.jfree.chart.ChartFactory;
import org.jfree.data.DefaultPieDataset;

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
//chart.setBackgroundPaint(Color.white);
//adjust pie-chart settings
Pie3DPlot pie3dplot = (Pie3DPlot)chart.getPlot();
pie3dplot.setStartAngle(360);
pie3dplot.setDirection(Rotation.CLOCKWISE);
pie3dplot.setBackgroundPaint(Color.lightGray);
pie3dplot.setSectionPaint(0,Color.green);
pie3dplot.setSectionPaint(1,Color.blue);
pie3dplot.setForegroundAlpha(0.5F);
pie3dplot.setNoDataMessage("No data to display");
//Types of labels
//NO_LABELS, NAME_LABELS, VALUE_LABELS, PERCENT_LABELS, NAME_AND_VALUE_LABELS, NAME_AND_PERCENT_LABELS, VALUE_AND_PERCENT_LABELS
pie3dplot.setSectionLabelType(PiePlot.VALUE_AND_PERCENT_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
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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
Sheriff

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]
 
Don't get me started about those stupid light bulbs.
 
subject: Any1 know drawin pie chart using jfreechart