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

How to put labels on the sections of the pie charts

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code to display the chart.
Now in this, there are two sections of the pie chart ,
I want to put labels on these two sections of the pie charts.
Can anybody help me out?

import java.awt.AWTException;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.RenderingHints;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.ColorModel;
import java.math.BigDecimal;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.entity.PieSectionEntity;
import java.text.*;

public class ChartDrawDemo extends JFrame{
private static final long serialVersionUID = 1L;
private DefaultPieDataset datasetcls;
private JFreeChart jfccls;

int count1 = 10;
int count2 = 20;
public ChartDrawDemo() {
datasetcls = new DefaultPieDataset();
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
} catch (InstantiationException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (IllegalAccessException ex) {
ex.printStackTrace();
}

this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
setVisible(false);
}
});

this.setTitle("CR Charts");
this.setSize(600,430);
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setValueClassification("A",new Double(10));
this.setValueClassification("B",new Double(20));
this.setCharClassification("CR Based on Classification");
this.Show();
}

public void setValueClassification(String title, Double numDouble) {
datasetcls.setValue(title, numDouble);
}
public void setCharClassification(String title) {
jfccls = ChartFactory.createPieChart(title, datasetcls, true, true, false);
PiePlot ppcls = (PiePlot) jfccls.getPlot();
ppcls.setSectionOutlinesVisible(false);
ppcls.setCircular(true);
ppcls.setLabelFont(new Font("SansSerif", Font.PLAIN, 8));
ppcls.setNoDataMessage("No Data Available");
ppcls.setLabelGenerator(null);
ppcls.setLabelGap(0.02);
}
private JPanel createPanelClassification() {
return new ChartPanel(jfccls,400,400,400,400,400,400,true,true,true,true,true,true);
}
public void Show() {
add(createPanelClassification());
setVisible(true);
}
public static void main(String[] args) {
ChartDrawDemo ce = new ChartDrawDemo();
}
}
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say you need something like


Please UseCodeTags when posting code of any length. Unformatted code is unnecessarily hard to read.
[ May 01, 2008: Message edited by: Ulf Dittmer ]
 
Come have lunch with me Arthur. Adventure will follow. 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