• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Any1 know drawin pie chart using jfreechart

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm afraid that "Mingyu" doesn't suffice for a display name either.
Note that we require a display name of the format FIRST_NAME(S) + SPACE + LAST_NAME.
Moving this to the Other Open Source Projects forum...
[ April 13, 2004: Message edited by: Dirk Schreckmann ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic