This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Any1 know drawin pie chart using jfreechart

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Moving this to the Other Open Source Projects forum...
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic