Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to put labels on the sections of the pie charts  RSS feed

 
Snehanshu Chatterjee
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();
}
}
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!