Key on the use of JFreeChart and Cewolf

xiaoxiao2021-03-06  65

1. Generate a different type of data set

Charts and datasets To create a chart using JFreeChart, you must create a Dataset, which you then use to create a JFreeChart. A Dataset contains the data that displays in the chart. JFreeChart features many different Dataset objects, which you can use to create assorted types of charts. Once you create a Dataset, you next create the actual chart. JFreeChart uses an object appropriately named JFreeChart to represent charts. you create JFreeChart objects from Dataset objects with the ChartFactory class. In the following examples, we will create pie, XY, AND Bar Charts Along with Their Corresponding DataSet Objects.

Pie chart A pie chart is created from a PieDataset. The following example creates a PieDataset using the DefaultPieDataset class, adds two values ​​via the setValue () method, and then creates a pie chart with the ChartFactory's createPieChart () method. This example will create A Pie Chart with the title "Sample Pie Chart," A Legend, And Two Slices: JavaWorld With 75 Percent of the Pie, And Other with The Other 25 Percent:

DEFAULTPIEDATSET PIEDATASET = New Defaultpiedataset (); Piedataset.SetValue ("JavaWorld", New Integer (75)); Piedataset.SetValue ("Other", New Integer (25));

JFreechart Chart = ChartFactory.createPiechart ("Sample Pie Chart", // Title Piedataset, // Dataset True // Show Legend);

XY chart An XYDataset can create area, line, and step XY charts. The following example creates an XYDataset from a series of data containing three XY points. Next, ChartFactory's createAreaXYChart () method creates an area XY chart. In addition to parameters for title , DataSet, And Legend () Takes in the labels for the x and y ax xiseries series = new xyseries; series.add (20.0, 10.0); Series.Add (40.0, 20.0); Series.Add (70.0, 50.0); xydataset xydataset = new xyseriescollection

JFreeChart Chart = ChartFactory.createAreaxychart ("Sample Xy Chart", // Title "Height", // X-Axis Label "Weight", // Y-Axis Label Xydataset, // DataSet true // show legend;

Bar chart A CategoryDataset can create numerous different charts, including horizontal and vertical bar charts. The following example creates a CatagoryDataset with two series of data and two categories, and then creates a 3D vertical bar chart from this dataset. This example creates a chart that Compares The Sales Growth in Two Quarters over Two Years:

String [] seriesNames = new string [] {"2001", "2002"}; string [] categoryNames = new string [] {"first quater", "second quater"}; Number [] [] categoryData = new integer [ ] [] {{new Integer (20), new Integer (35)}, {new Integer (40), new Integer (60)}}; CategoryDataset categoryDataset = new DefaultCategoryDataset (seriesNames, categoryNames, categoryData); JFreeChart chart = ChartFactory .CreateVerticalBarchart3d ("Sample Category Chart", // Title "Quarters", // X-Axis Label "Sales", // Y-Axis Label CategoryDataSet, // DataSet True // show legend; use the CEWOLF label library to develop graphics, only need productDataSet

http://cewolf.sourceforge.net/

DataSetProducer XYDATA = New DataSetProducer () {public object produted () {xyseries xys = new xyseries ("eXample xy dataset"); double last = 0.0; for (int i = -50; i <= 50; i ) { Double y = last (math.random () * 100) - 50.0); xys.add ((Double) i, y); Last = Y;} return new xyseriescollection (xys);} public string getProducerId ()} return "XYDataProducer";} public boolean hasExpired (Map params, Date since) {return false;}}; achieve mouse clicks and tips LinkGenerator xyLG = new XYItemLinkGenerator () {public String generateLink (Object data, int series, int item) {return "#Series" series;}}; pageContext.setAttribute ( "xyLinkGenerator", xyLG); CategoryToolTipGenerator catTG = new CategoryToolTipGenerator () {public String generateToolTip (CategoryDataset dataset, int series, int index) {return String.valueOf ( DataSet.getValue (Series, Index));}}; pageconText.setttribute ("categorytooltipgenerator", cattg);

PietooltipGenerator PIETG = New PietooltipGenerator () {public string generateTooltip (Piedataset Dataset, Comparable Section, INDEX) {Return String.Valueof (Index);}}

转载请注明原文地址:https://www.9cbs.com/read-85407.html

New Post(0)