Question

Is it possible to draw a 3D chart using JfreeChart like in the following link.If possible can anyone give some hints and some snippets of code on what parameters of Plot can be used to do this.

link text

Was it helpful?

Solution

It's possible though it won't look exactly the same. The easiest way is to create a dataset (descendant of org.jfree.data.general.PieDataset) and use one of org.jfree.chart.ChartFactory methods:

PieDataset data = new DefaultPieDataset();
data.setValue("Section1", 30);
data.setValue("Section2", 60);
data.setValue("Section3", 120);
JFreeChart pieChart = ChartFactory.createPieChart3D(
 "My Pie Chart", // title
 data,           // data set
 true,           // draw a legend
 true,           // show tooltips over sections
 false);         // do not generate image map with URLs

You can then further customize your chart through pieChart methods. For example, here's how to explode one pie section:

 PiePlot plot = (PiePlot) pieChart.getPlot();
 plot.setExplodePercent("Section2", 0.25);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top