Chart
Recently because of the project needs, began to learn Jfreechart and itext, on the Internet to find a relevant information is not a lot, especially jfreechart in the official document did not like Itext as detailed description and examples, and the official demo only a jar file, which is also more chaotic , do not know where to start, on the Internet to find a few examples, began to learn it step-by-step!
The first example is written by Taiwanese, and many nouns are used in Taiwanese parlance, and friends who have read the books of Mr. Houtie should have a deep understanding of them! Learning any open source project the first task is to match the environment,
There are three main steps to creating a Jfreechart image
Create a DataSet with a dataset to create jfreechart for Jfreechart make some custom designs Jfreechart
The first step: setting Up a DataSet
Barchart uses the DataSet interface to org.jfree.data.CategoryDataset the dataset. There are two ways to build a categorydataset
Using the Categorydataset subclass Org.jfree.data.DefaultCategoryDataset, and then using AddValue () to add the data to the dataset to create a two array containing the numbers, Then use the Org.jfree.data.DatasetUtilities createcategorydataset ()
Using Defaultcategorydataset
Defaultcategorydataset class:
public void AddValue (double value, java.lang.Comparable Rowkey, java.lang.Comparable columnkey) public void AddValue ( Java.lang.Number value, java.lang.Comparable rowkey, java.lang.Comparable Columnkey)
Title-the Chart title.categoryaxislabel-the label for the category Axis.valueaxislabel-the label for the value axis Data-the DataSet for the chart.orientation-the plot orientation (plotorientation.horizontal or Plotorientation.vertica L). legend-a flag specifying whether or not a legend was Required.tooltips-configure chart to generate tool- Configure chart to generate URLs?
Chartpanel is a kind of inheritance jpanel, which is responsible for showing the Jfreechart in the application. We simply pass the Jfreechart as a reference to Chartpanel's construction. After making the Chartpanel, set the size, and then add the ContentPane to the General panel.
Chartpanel class:
Public Chartpanel (Jfreechart chart) public Chartpanel (Jfreechart chart, Boolean Usebuffer) public Chartpanel (Jfreechart Chart, Boolean properties, Boolean Save, Boolean print, Boolean zoom, Boolean tooltips) public Chartpanel (Jfreechart chart, int width, int height, int minimumdrawwidth, int minimumdrawheight, int maximumdrawwidth, int maximumdrawheight, Boolean Usebuffer, Boolean properties, Boolean Save, Boolean print, Boolean zoom, Boolean tooltips)
Chart-the chart.usebuffer-a flag Controlling whether or not a off-screen buffer is USED.PROPERTIES-A flag Indicatin G whether or not the Chart property editor should is available via the popup Menu.save-a flag indicating whether or not Save options should be available via the popup Menu.print-a flag indicating whether or not the "Print option should be AV Ailable via the popup menu.zoom-a flag indicating whether or not zoom options should is added to the popup menu.tooltips -a flag indicating whether or not ToolTips should is enabled for the Chart.width-the preferred width of the Panel.heig Ht-the preferred height of the panel.minimumdrawwidth-the minimum drawing width.minimumdrawheight-the minimum Drawin G height.maximumdrawwidth-the Maximum drawing width.maximumdrawheight-the maximum drawing height.
Public Hellobarchart () {Categorydataset DataSet = CreateDataSet (); Jfreechart chart = Createchart (DataSet); Chart = Customizechart (chart); Chartpanel Chartpanel = new Chartpanel (chart); Chartpanel.setpreferredsize (New Dimension (500, 270)); Getcontentpane (). Add (Chartpanel); Pack (); SetVisible (TRUE); Setdefaultcloseoperation (Jframe.exit_on_close); }
So far the first example has been completed, the basic understanding of Jfreechart some of the basic technology! Here's another example of a columnar chart.
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.