I have created the Pie chart same as in PieChartDemo1. I have created an Applet and added the ChartPanel in it and displayed it on the brower by accessing the applet. But the problem is that Pie chart is not showing the Legend. Can anyone tell me why? I have used the same approach to create Bar Charts and line charts and their legends are shown on the applet but why not for Pie Chart? Here is my code.
Code: Select all
import java.applet.*;
import java.awt.Font;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
public class TestApplet extends Applet{
public void init() {
this.add(new ChartPanel(createChart(createDataset())));
}
private static PieDataset createDataset()
{
DefaultPieDataset defaultpiedataset = new DefaultPieDataset();
defaultpiedataset.setValue("One", new Double(43.200000000000003D));
defaultpiedataset.setValue("Two", new Double(10D));
defaultpiedataset.setValue("Three", new Double(27.5D));
defaultpiedataset.setValue("Four", new Double(17.5D));
defaultpiedataset.setValue("Five", new Double(11D));
defaultpiedataset.setValue("Six", new Double(19.399999999999999D));
return defaultpiedataset;
}
private static JFreeChart createChart(PieDataset piedataset)
{
JFreeChart jfreechart = ChartFactory.createPieChart("Pie Chart Demo 1", piedataset, true, true, false);
TextTitle texttitle = jfreechart.getTitle();
texttitle.setToolTipText("A title tooltip!");
PiePlot pieplot = (PiePlot)jfreechart.getPlot();
pieplot.setLabelFont(new Font("SansSerif", 0, 12));
pieplot.setNoDataMessage("No data available");
pieplot.setCircular(false);
pieplot.setLabelGap(0.02D);
return jfreechart;
}
}
Thanks