public string Getchart (string series[],double score[][],string type[],string name) {
final int num=8;
Defaultcategorydataset defaultcategorydataset = new Defaultcategorydataset ();
for (int i=0;i<type.length;i++) {
Type[i]=type[i].substring (0, (Type[i].length () <num)? Type[i].length (): num);
}
for (int j=0;j<series.length;j++) {
int i=0;
for (i=0;i<type.length;i++) {
Defaultcategorydataset.addvalue (Score[j][i], series[j], type[i]);
}
}
Jfreechart Jfreechart = Chartfactory.createlinechart (Name,null,null,defaultcategorydataset, Plotorientation.vertical,true,true,false);
Jfreechart.getlegend (). SetPosition (Rectangleedge.right);
Jfreechart.setbackgroundpaint (Color.White);
Categoryplot Categoryplot = (categoryplot) jfreechart.getplot ();
Categoryplot.setnodatamessage ("Countless evidence available!") ");
Categoryplot.setbackgroundpaint (Color.White);
Categoryplot.setdomaingridlinesvisible (TRUE);
Categoryplot.setrangegridlinesvisible (TRUE);
Categoryplot.setrangegridlinepaint (Color.gray);
Categoryplot.setdomaingridlinepaint (Color.gray);
Categoryplot.setbackgroundalpha (0.8f);
Font font1 = new Font ("bold", Font.Bold, 14);
Jfreechart.gettitle (). SetFont (FONT1);
Font font3 = new Font ("script", Font.Bold, 12);
Jfreechart.getlegend (). Setitemfont (FONT3);
Categoryaxis Categoryaxis = Categoryplot.getdomainaxis ();
Categoryaxis.setcategorylabelpositions (CATEGORYLABELPOSITIONS.UP_45);
Categoryaxis.setmaximumcategorylabellines (10);//line number, set according to need
Categoryaxis.setmaximumcategorylabelwidthratio (0.5f);//width of each line, set a width of Chinese characters here
Numberaxis Numberaxis = (numberaxis) categoryplot.getrangeaxis ();
Numberaxis.setstandardtickunits (Numberaxis.createintegertickunits ());
Numberaxis.setautorangeincludeszero (TRUE);
Numberaxis.setrangewithmargins (0, 3);
Numberaxis.setuppermargin (0.8)////set the highest one Item to the top of the picture distance
Numberaxis.setupperbound (3.5);/Ordinate maximum value
Categoryaxis.setticklabelfont (New Font ("Song Body", Font.Bold, 12));
Numberaxis.setticklabelfont (New Font ("Official script", Font.Bold, 12));
Font font2 = new Font ("SimSun", Font.Bold, 16);
Categoryaxis.setlabelfont (Font2);
Numberaxis.setlabelfont (Font2);
Categoryplot.setaxisoffset (New Rectangleinsets (0D, 0d,0d, 10D))//Set the distance between the graph and the XY axis
Lineandshaperenderer lineandshaperenderer = (lineandshaperenderer) categoryplot.getrenderer ();
Lineandshaperenderer.setshapesvisible (TRUE); Data points visible
Lineandshaperenderer.setseriesstroke (0, New Basicstroke (2.0F, 1, 1, 1.0F, new float[] {
10F, 6F
}, 0.0F)); Define the line between the series points, which is dotted, and the default is a straight line
Lineandshaperenderer.setseriesstroke (1, New Basicstroke (2.0F, 1, 1, 1.0F, new float[] {
6F, 6F
}, 0.0F));
Lineandshaperenderer.setbaseitemlabelsvisible (TRUE);
Lineandshaperenderer.setbaseitemlabelgenerator (New Standardcategoryitemlabelgenerator ());
Chartrenderinginfo info=new Chartrenderinginfo (New Standardentitycollection ());
String fileName = null;
Try
{
FileName = Servletutilities.savechartaspng (Jfreechart, 700,300, info, NULL);//Generate Picture
}
catch (IOException E)
{
E.printstacktrace ();
}
String Graphurl = "/projectname/displaychart?filename=" + filename; ProjectName is the path to the corresponding project, which is usually the project name
This is used in JSP: String Graphurl = Request.getcontextpath () + "/servlet/displaychart?filename=" + filename;
Return graphurl;//returns the address of the generated picture
}