I am trying to create a simple 3d pie chart using jfreechart in NetBeans IDE.My code is given below :-
DefaultPieDataset pieDataset = new DefaultPieDataset();
pieDataset.setValue("One", new Integer(10));
pieDataset.setValue("Two", new Integer(20));
pieDataset.setValue("Three", new Integer(30));
pieDataset.setValue("Four", new Integer(40));
JFreeChart chart = ChartFactory.createPieChart("Pie Chart", pieDataset,true,true,false);
PiePlot3D plot = (PiePlot3D) chart.getPlot (); // <--error in this line
However, the last line shows the error "Incompatible types : Plot cannot be converted to piePlot3D" . Many examples i found on the internet uses the same line of code without any error. I have included all the necessary imports but still the error is shown. How can I fix this error?
You need to use the createPieChart3D() method in the ChartFactory class (you missed the '3D' on the end of the method name).
You should also look at the 3D pie charts in Orson Charts - these use real 3D projections, so they are a bit nicer. I am the author of both libraries.