Jfreechart is an excellent open source Java 2D Project, the disadvantage of which is the lack of documentation, both in English and Chinese. This article is the second part of the empirical summary
The coordination relation of the object of the Jfreechart drawing class
The Jfreechart drawing object is composed of a org.jfree.chart.JFreeChart, but as the key graphich2d of the drawing is arranged after the corresponding render class in the org.jfree.chart.render.*. In other words, developers can complete the necessary drawing-predetermined effects by setting the base-board graphic, and most of the modifications can actually be done by wrapping the various classes without directly modifying the graphic object properties (who remembers?). )。 The Jfreechart data interface is packaged by different plot in org.jfree.chart.plot.*, which corresponds to a different dataset, which is packaged in different dataset interfaces in Org.jfree.chart.data.*. The key to using Jfreechart is to produce a corresponding DataSet object, and then wrap it into the corresponding drawing set plot object, and then wrap it into different Jfreechart objects to deliver output. The new method allows you to step through the steps above. In other words, the plot class is the graphic design, the render is the tool to draw, and the dataset is the populated data, so the three key elements of the drawing are abstracted into a unified interface, each of which is to be paired with a variety of graphs. For graphs that may have multiple sets of data, such as multiple curves of a time series (like several stocks), the incoming plot is not a dataset, but a collection of datasets, generally named So-and-so collection.
By chartfactory different methods to generate different chart types, we can reduce the amount of operation code of different chart objects by dataset, and get chart object directly. In fact, the factory class instead of the user to generate the necessary render and plot classes, if the user does not want to use the default settings, you need to get the corresponding plot object to modify. The final image output of the Jfreechart is typically completed by the org.jfree.chart.ChartUtilites, which can output chart objects to the PrintWriter object that is being finalized. In the server program, another Serverutilites method calls this method, generates an image temp file, returns the file object to the JSP or servlet, and, by binding the lifecycle of the image to the session, hopes to implement the Buffering function, Reduce the loss of server dynamic image generation. But there is a big problem is that if the session is very long, it is tantamount to not generate real-time images, the second is to visit more people, the burden of the server seems to have increased. This algorithm obviously has a problem, it is better to modify the time to update an image more appropriate.
Observe the code, the effect is the same:
A, factory Method:
Jfreechart chart = Chartfactory.createpiechart3d ("GDP distribution scale graph", data, True, false, false);//Specify a different implementation chart object, containing no The same plot drawing object Pieplot plot = (Pieplot) chart.getplot ();//Get the plot object to revise the properties and force the styling to invoke the respective method Plot.setlabelgenerator (new Standardpieitemlabelgenerator ("{0} = {2}", Numberformat.getnumberinstance (), Numberformat.getpercentinstance ())); /Set Annotation mode Plot.setforegroundalpha (0.5f);//Set Transparency Plot.setnodatamessage ("no record Content");/no record abnormal display
B, manually generated objects
Pieplot plot = new Pieplot (dataset);
Plot.setlabelgenerator (New Standardpieitemlabelgenerator ("{0} = {2}", Numberformat.getnumberinstance (), Numberformat.getpercentinstance ())//Set annotation mode Plot.setforegroundalpha (0.5f);//Set Transparency Plot.setnodatamessage ("no record content" );//no record abnormal display
Jfreechart chart = new Jfreechart ("", Jfreechart.default_title_font, Plot, false);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.