Insert 3D Chart in PDF JFreeChart iText Java Example Tutorial

We earlier discussed how to insert a 2D chart into a PDF document using iText and JFreeChart.This example can be easily extended towards creating a 3D chart using JFreeChart and inserting the 3D chart into the PDF document using iText. If you follow the Java Code in the earlier example, you just have to make one minor method change in the code to get a 3D chart for you. Can it be much easy than anything?

If you are not keen in a 2D bar chart but would like to have a 3D chart inserted into the PDF file, replace the following line of code from the previous example to the one shown below;
//JFreeChart my2DChart=ChartFactory.createBarChart("Mark Details","Subject","Marks",mychartData,PlotOrientation.VERTICAL,false,true,false);
JFreeChart my2DChart=ChartFactory.createBarChart3D("Mark Details","Subject","Marks",mychartData,PlotOrientation.VERTICAL,true,true,false);                                              
If you look at the change above, we have just refrained ourselves from using createBarChart method. Instead we use a new method of ChartFactory instance. This method is createBarChart3D which will return a three dimensional bar chart for us as a JFreeChart object. We can then follow the same approach used in the previous example to push this chart into a PDF document. The 3D bar chart inserted into a PDF file is shown below;
JFreeChart iText - 3D Chart Example
JFreeChart iText - 3D Chart Example
Now, this chart has legend information added to it at the bottom. We have enabled it in the createBarchart3D method by passing the "true" for the flag (third from right) that enables legend information against a chart in a PDF.We are going to cover much more chart patterns for inserting into PDF file using JFreeChart in the upcoming tutorials. Stay tuned to this space for more

No comments:

Post a Comment