JFreeChart is the most widely used library for creating charts as it provides a lot to features out of the box. It has common classes used by JFreeChart to provide global utility functions. Creating charts with JFreeChart is a three step process. Before starting with the demos we need to configure the JFreeChart library. It is very easy; we need to follow the following steps:.
Pie charts are used to visually represent percentage of the whole at a given point in time. The pie chart is a circular chart and has sectors with size proportional to the data represented by that sector. For this demo we will create a pie chart to represent the market share of different mobile manufacturers in a particular quarter.
The data used here is not actual data, but fictitious data created for demo purpose. The first step in creating the chart, as we have already discussed, is to create the dataset for the data to be displayed in chart. For pie chart data we need the dataset that implements org. PieDataset interface of JFreeChart. JFreeChart provides an implementation class for this interface which we will use. This class is org. Using this class we can create the data for pie chart like following:.
The next step is to create the pie chart. JFreeChart has provided a ChartFactory class that we use for creating various types of charts. For creating we need to invoke createPieChart method of this factory. In the above code we are passing a reference to the dataset object that we created. This is used by JFreeChart to get the data while drawing the chart. There are many ways of customizing the charts, those we will explore later. For this demo we have used the default values for various attributes.
The final step is to display the chart on the target source. For this demo purpose we will display the chart in a frame on the screen. We need to do the following for displaying chart this way:. TableOrder ;. CategoryDataset ;. IntervalCategoryDataset ;. DefaultPieDataset ;. PieDataset ;. WaferMapDataset ;. BoxAndWhiskerCategoryDataset ;. IntervalXYDataset ;. OHLCDataset ;.
TableXYDataset ;. WindDataset ;. XYDataset ;. XYZDataset ;. This will be applied to all new charts. Each section can have a shade of red or. GREEN ;. RED ;. PLAIN , 10 ;. The chart object. CategoryDataset dataset , TableOrder order , boolean legend ,. PieToolTipGenerator tooltipGenerator. The chart object returned by this method uses a. CategoryDataset dataset , PlotOrientation orientation ,. The chart object returned. IntervalCategoryDataset dataset , boolean legend , boolean tooltips ,. The chart object returned by this method.
StandardCategoryToolTipGenerator generator. BLACK ;. PlotOrientation orientation , boolean legend , boolean tooltips ,. ValueAxis domainAxis;. XYToolTipGenerator tt;. String title , String xAxisLabel ,. AREA , tipGenerator,.
The chart object returned by this. A time series chart is an. The default renderer is an. The chart is composed of.
This chart is constructed with an. Add jars to build path of your project In your project create a folder "lib", and paste the JFreeChart jars into this folder. Code Create the following two classes.
JFrame ; import org. ChartFactory ; import org. ChartPanel ; import org. JFreeChart ; import org. PiePlot3D ; import org. DefaultPieDataset ; import org. PieDataset ; import org.
0コメント