Create image using JFreeChart

xiaoxiao2021-03-06  116

One: JFreeChart introduction JFreeChart is a Java tool for creating a picture free of charge. You can create a graphic (Pie Charts;) Cartes (Line Charts) Horizontal / Vertical Bar Charts Gantt chart (Gantt Charts;) XY plots and scatter plots; time series, high / low / open / close charts and candle stick charts; combination charts; Pareto charts; bubble charts; wind plots, meter charts and symbol charts; you can see the graphic jfreechart that can be created from the following address Type http://www.jfree.org/jfreechart/samples.htmlsourceForge There is a JFreeChart-based project CEWOLF can be very convenient to create pictures in JSP / Servlets JFreechart (2003-05-08) version is 0.98 I hope Information or Download JFreeChart Please visit the following sites: http://www.jfree.org/jfreechart/ 2: Special instructions: JFreeChart is an open source project, but the document is 40 US dollars to buy. There is also a very important issue. If JFreeChart uses Chinese, the Chinese who uses the default font display will be very vague, you may need to modify the source code.

Let me take a few simple examples to explain how to create pictures using JFreeChart In the development, you may import the following iMport com.jrefinery.chart.chartfactory; import com.jrefinery.chart.chartutilities; import com.jrefinery.Chart .JFreeChart; import com.jrefinery.chart.TextTitle; import com.jrefinery.chart.axis.NumberAxis; import com.jrefinery.chart.plot.CategoryPlot; import com.jrefinery.chart.plot.PiePlot; import com.jrefinery. data.Day; import com.jrefinery.data.DefaultCategoryDataset; import com.jrefinery.data.DefaultPieDataset; import com.jrefinery.data.TimeSeries; import com.jrefinery.data.TimeSeriesCollection; import com.jrefinery.data.TimeSeriesDataPair; in After 0.98, the package was changed from com.jrefinery. * Changed to: Org.jfree 3: Create Pie Diagram / / Picture Title String Title = "Air Conditioning 2002 Market Posage"; // Setting Data Source Defaultpiedataset Piedata = New Defaultpiedataset (); // The first parameter is name, the second parameter is Double number Piedata.SetValue ("Lenovo", 27.3); Piedata.SetValue ("Great Wall", 12.2); Piedata.SetValue ("Haier", 5.5); Piedata .SetValue ("Beautiful", 17.1); Piedata.SetValue ("Panasonic", 9.0); Piedata.SetValue ("科龙", 19.0); // Create JFreeChart, use ChartFactory to create JFreechart, very standard factory design Pattern jfreechart chart = chartfact ORY.CREATEPIECHART (Title, Piedata, true, true, true); // Settings a picture title Chart.SetTitle (New TextTitle (Title, New Font ("Lishu", Font.italic, 15)))); // Chart. AddSubtitle (New TextTitle ("2002 FYRATE", New Font ("Lishu", Font.ItAlic, 12)))); // Setting the background chart.setBackgroundPaint (color.white); // chart.s // Pie FIG using a PiePlot PiePlot pie = (PiePlot) chart.getPlot (); // pie.setSectionLabelType (PiePlot.NAME_AND_PERCENT_LABELS); pie.setSectionLabelType (PiePlot.NAME_AND_VALUE_LABELS); // set the display format (or name plus a percentage value) PIE .SetPercentFormatString ("#, ### 0.0 #%"); // Set the percentage display format Pie.setBackgroundPaint (color.White); Pie.setSectionLabelfont (New Font ("Black Body", Font.TrueType_Font, 12));

// Set the background transparency (between 0-1.0) PIE.SetBackgroundalpha (0.6F); // Set the foreground transparency (between 0.0-1.0) PIE.SETFOREGROUNDALPHA (0.90F); // Output file to the specified directory String RFNAME = Mathutil.GetroundCode (12) ".jpeg"; string filename = "d: / test /" RFNAME; try {// can save the file as JPG or PNG format.

ChartUTILITIES.SAVECHARTASJPEG (New File (Filename), 100, CHART, 600, 600); // The first parameter is file name // second parameter quality // Which Chart is created to create a picture // fourth Width // Fifth Height} Catch (IOException Exz) {System.out.Print (".... Cant't create Image file");} actually created a picture using JFreeChart is simple, different picture type difference Data set four: Create a graph // Create a default chart based on some sample data ... // Curve Title String Title = "Trend Analysis"; // Curve X-axis prompt String Domain = "Month Trend" ; // Curve Y axis prompt String Range = "Results"; // Curve Title String SubtitleStr = "2003 FYRAT Analysis"; // Creating Time Data Source // Each TimeSeries is a curve on the map TimeSeries Ca = New TimeSeries; for (int i = 1999; i <2005; i ) {for (int mon = 0; MON <12; MON ) {//ca.add(NEW MONTH (Mon 1, i), new double (500 math.random () * 100)); // TimeSeriesDataPAir is a time point in the numerical embodying Ca.Add (New Day (1, MON 1, I), New Day Double (500 math.random () * 100)))))))))))))))))));}} TimeSeries IBM = New TimeSeries; for (INT i = 1999; i <2005; i ) {for (int MON = 0; MON <12; MON ) {//ibm.add(new Month (MON 1, I), New Double (400-math.random () * 100)); IBM.Add (New TimeSeriesDataPair (New Day (1, MON 1, I), N EW Double (400 - math.random () * 100))));}} TimeSeries King = New TimeSeries ("East"); for (int i = 1999; i <2005; i ) {for (int MON = 0; MON <12; MON ) {//ibm.add(new Month (MON 1, I), New Double (400-math.random () * 100); king.add (New TimeSeriesDataPair (New Day (1, MON 1, I), New Double (300 - math.random () * 100)))));}}} // Time Curve Data Collection TimeSeriescollection DataSet = New TimeSeriesCollection (); Dataset.AddSeries (CA); Dataset.AddSeries IBM); dataset.addseries (king); // dataset.addseries (jpy); // dataset.addseries (MAV);

// time curve element JFreeChart chart = ChartFactory.createTimeSeriesChart (title, domain, range, dataset, true, true, false); // then customise it a little ... TextTitle subtitle = new TextTitle (subtitleStr, new Font ( "bold ", Font.bold, 12); chart.addsubtitle (subtitle); Chart.SetTitle (New TextTitle (Title, New Font (" Lishu ", Font.Ilic, 15)); // Pie.setseriesLabelfont (New Font) ("Black Body", Font.Bold, 15); Chart.SetBackground (New GradientPaint (0, 0, Color.White, 0, 1000, Color.Blue)); // sysout // Output file to the specified directory String RFNAME = Mathutil.GetroundCode (22) ".jpeg"; string filename = "d: / test /" RFNAME; try {//for/system.out.println(); ChartUTILITIES.SAVHARTASJPEG (NEW File (filename) , 100, Chart, 600, 600); // log.info (".... CREATE Image File:" filename);} catch (ioException exz) {system.out.print (".... cant" T create image file ");} 5: Create a histogram string title =" column map test "; string domain =" unit comparison "; string Range =" Numerical "; // categoryDataSet Data = DemodatasetFactory.createcategoryDataSet (); defaultcategoryDataSet Data = new defaultcategoryDataSet (); for (i NT R = 0; R <5; R ) {string rower = "unit [" (R 1) "]"; // First layer loop: Analyze object for (int C = 0; C <6; C ) {// Second layer loop: Analyze the data in time at time point String Columnkey = "2001" (C 1) "Month"; DATA.ADDVALUE (New Double (r * C 5), rowKey, columnKey);}} JFreeChart chart = ChartFactory.createVerticalBarChart (title, domain, range, data, true, true, false); // then customise it a little ... chart.setBackgroundPaint (new GradientPaint (0, 0, Color.White, 1000, 0, Color.Red); Chart.Settitle (New TextTitle (Title, New Font ("Lishu"

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

New Post(0)