I am trying to generate a piechart from an existing application but am getting errors. The latest error is:
createPieChart(java.lang.String,org.jfree.data.general.PieDataset,org.jfree.chart.labels.PieSectionLabelGenerator) in efa.util.chart.ChartUtil cannot be applied to (java.lang.String,org.jfree.data.general.PieDataset) [javac] sectorChart = ChartUtil.createPieChart("",xy); [javac] ^
Besides this, I also need to add a third argument in the function call, which is PieSectionLabelGenerator labelGenerator. However, I don't know how to do that. Have read the docs/api but still am unsure. What would you advise?
The code I am using is
imports (please see below)
declaration in the code is JFreeChart sectorChart;
the function:
private void genChart(){
DefaultPieDataset pieDataset = new DefaultPieDataset();
pieDataset.setValue("JavaWorld", new Integer(75));
pieDataset.setValue("Other", new Integer(25));
PieDataset xy = pieDataset;
sectorChart = ChartUtil.createPieChart("",xy,);
}
I don't think there is anything wrong with my imports, nor declaration of the object. Please let me know if you'd like to see these, I'm leaving them out for brevity of this post.
I'm unable to make the answer below work for my app specifically. But I have this fragment of code in my ChartUtil.java file
public static JFreeChart createPieChart(final String title,
final PieDataset dataset, PieSectionLabelGenerator labelGenerator) {
final JFreeChart chart = ChartFactory.createPieChart(title, dataset,
false, true, true);
labelGenerator = labelGenerator != null ? labelGenerator
: new StandardPieSectionLabelGenerator("{2} {0}",
NumberFormat.getNumberInstance(),
NumberFormat.getPercentInstance());
PiePlot plot = (PiePlot) chart.getPlot();
ChartUtil.formatPiePlot(plot);
plot.setLabelGenerator(labelGenerator);
PieRenderer renderer = new PieRenderer();
renderer.setColor((PiePlot) chart.getPlot(), dataset);
return chart;
}
I believe we need to figure out how to pass a PieSectionLabelGenerator into the function as an argument...