Some examples of usage of Jfreechart

Source: Internet
Author: User

Public abstract class Abstractstatistic implements statistic {

/**
* Create a statistical graphic
*
* @param Columnkeys
* Key word Group
* @param data
* Data Array
* @param title
* Title
* @param session
* @param Rowkeys
* Line key word
* @param showtype
* @return
*/

Public String createstatisticimg (string[] Columnkeys, double[][] data,
String title, HttpSession session, string[] Rowkeys, string showtype) {
try {

Jfreechart chart = null;
if (Showtype.equals ("1")) {
Chart = Createbarchart3d (data,columnkeys,rowkeys,title);
}
if (Showtype.equals ("2")) {
Chart = Createlinechart (data,columnkeys,rowkeys,title);
}
if (Showtype.equals ("3")) {
Chart = Createareachart (data,columnkeys,rowkeys,title);
}
if (Showtype.equals ("4")) {
Chart = Createlinechart3d (data, Columnkeys, Rowkeys, title);
}
String filename = servletutilities.savechartaspng (chart, 800, 450,
NULL, session);
return filename;
catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
Return "";
}

Public Jfreechart Createbarchart3d (double[][] data, string[] Columnkeys, string[] rowkeys,string title) {


Categorydataset DataSet = Datasetutilities.createcategorydataset (
Rowkeys, Columnkeys, data);

Jfreechart chart = Chartfactory.createbarchart3d (title,//"Distribution and Contrast map")
"", NULL, DataSet, Plotorientation.vertical, True, False,
FALSE);

Chart.setbackgroundpaint (Color.White)//Set whole picture background color
Categoryplot plot = Chart.getcategoryplot ();
Plot.setbackgroundpaint (Color.gray);//Set the background color of the graphics area
Set whether vertical gridlines are displayed
Plot.setdomaingridlinesvisible (TRUE);
Set whether horizontal gridlines are displayed
Plot.setrangegridlinesvisible (TRUE);
Categoryaxis Domainaxis = Plot.getdomainaxis ();
/*------To set the tilt of the X axis title----*
Domainaxis.setcategorylabelpositions (Categorylabelpositions.standard);
Domainaxis.setmaximumcategorylabellines (20);

Domainaxis.setticklabelfont (New Font ("bold", Font.plain, 12));

Plot.setdomainaxis (Domainaxis);

  valueaxis Rangeaxis = Plot.getrangeaxis ();
  //Sets the maximum distance between one Item and the top of the picture
  rangeaxis.setuppermargin (0.15);
  //set the distance between the lowest Item and the bottom of the picture
  rangeaxis.setlowermargin (0.15);
  plot.setrangeaxis (Rangeaxis);
  barrenderer3d renderer = new Barrenderer3d ();
  renderer.setbaseoutlinepaint (Color.Black);
  //Sets the Wall color <br>
  renderer.setwallpaint (Color.gray);
  //sets the color of each column
  renderer.setseriespaint (0, new color (255, 0, 0));
  renderer.setseriespaint (1, New Color (0, 0, 255));
  renderer.setseriespaint (2, New Color (0, 255, 0));

Outline the color of each column
Renderer.setseriesoutlinepaint (0, Color.Black);
Renderer.setseriesoutlinepaint (1, Color.Black);
Renderer.setseriesoutlinepaint (2, Color.Black);
Sets the distance between the parallel columns contained in each region
Renderer.setitemmargin (0.1);

Displays the value of each column and modifies the font properties of the value
Renderer.setseriesitemlabelgenerator (0,new
Standardcategoryitemlabelgenerator ("##%", Java.text.NumberFormat.getPercentInstance ());
Renderer
. Setitemlabelgenerator (New Standardcategoryitemlabelgenerator ());
Renderer.setitemlabelfont (New Font ("bold", Font.plain, 12));
Renderer.setitemlabelsvisible (TRUE);
Set the label display position, without adding this sentence will be displayed in the column body
Renderer.setpositiveitemlabelposition (New Itemlabelposition (
Itemlabelanchor.outside12, Textanchor.bottom_center));

Plot.setrenderer (renderer);
Set the transparency of the column <BR>
Plot.setforegroundalpha (0.6f);

Set area, sales location <BR>
Plot.setdomainaxislocation (Axislocation.bottom_or_left);
Plot.setrangeaxislocation (Axislocation.bottom_or_left);

return chart;

}


Public Jfreechart Createlinechart (double[][] data, string[] Columnkeys, string[] rowkeys,string title) {

Categorydataset DataSet = Datasetutilities.createcategorydataset (
Rowkeys, Columnkeys, data);

Jfreechart chart = Chartfactory.createlinechart (title,//"Regional distribution and contrast map"
"", NULL, DataSet, Plotorientation.vertical, True, False,
FALSE);
Categoryplot plot = Chart.getcategoryplot ();
Categoryaxis Domainaxis = Plot.getdomainaxis ();
/*------To set the tilt of the X axis title----*
Domainaxis.setcategorylabelpositions (CATEGORYLABELPOSITIONS.UP_90);
Domainaxis.setticklabelfont (New Font ("bold", Font.plain, 12));
return chart;
}

Public Jfreechart Createlinechart3d (double[][] data, string[] Columnkeys, string[] rowkeys,string title) {

Categorydataset DataSet = Datasetutilities.createcategorydataset (
Rowkeys, Columnkeys, data);

Jfreechart chart = Chartfactory.createlinechart3d (title,//"Regional distribution and contrast map"
"", NULL, DataSet, Plotorientation.vertical, True, False,
FALSE);
Categoryplot plot = Chart.getcategoryplot ();
Categoryaxis Domainaxis = Plot.getdomainaxis ();
/*------To set the tilt of the X axis title----*
Domainaxis.setcategorylabelpositions (CATEGORYLABELPOSITIONS.UP_90);
Domainaxis.setticklabelfont (New Font ("bold", Font.plain, 12));
return chart;
}

Public Jfreechart Createareachart (double[][] data, string[] Columnkeys, string[] rowkeys,string title) {
Categorydataset DataSet = Datasetutilities.createcategorydataset (
Rowkeys, Columnkeys, data);
Jfreechart chart = Chartfactory.createareachart (title, "Statistic Time", "Statistic Quantity", DataSet, Plotorientation.vertical, True, true, FALSE);
Chart.setbackgroundpaint (Color.White);
Categoryplot Categoryplot = (categoryplot) chart.getplot ();
Categoryplot.setforegroundalpha (0.5F);
Categoryplot.setaxisoffset (New Rectangleinsets (5D, 5 D, 5 D, 5D));
Categoryplot.setbackgroundpaint (Color.lightgray);
Categoryplot.setdomaingridlinesvisible (TRUE);
Categoryplot.setdomaingridlinepaint (Color.White);
Categoryplot.setrangegridlinesvisible (TRUE);
Categoryplot.setrangegridlinepaint (Color.White);
Categoryaxis Categoryaxis = Categoryplot.getdomainaxis ();
Categoryaxis.setcategorylabelpositions (CATEGORYLABELPOSITIONS.UP_45);
Categoryaxis.setlowermargin (0.0D);
Categoryaxis.setuppermargin (0.0D);
Categoryaxis.addcategorylabeltooltip ("Type 1", "the" "the");
Categoryaxis.addcategorylabeltooltip ("Type 2", "the second type.");
Categoryaxis.addcategorylabeltooltip ("Type 3", "the third type.");
Numberaxis Numberaxis = (numberaxis) categoryplot.getrangeaxis ();
Numberaxis.setstandardtickunits (Numberaxis.createintegertickunits ());
Numberaxis.setlabelangle (0.0D);
return chart;
}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.