200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > jsp怎么做柱状图_用jsp怎样生成柱状图 饼状图 折线图

jsp怎么做柱状图_用jsp怎样生成柱状图 饼状图 折线图

时间:2023-01-04 08:29:54

相关推荐

jsp怎么做柱状图_用jsp怎样生成柱状图 饼状图 折线图

展开全部

jsp生成柱状图,饼状图,折线图可以32313133353236313431303231363533e59b9ee7ad9431333339663338借助于jfreechart。

1、柱状图的生成源码:

/**

*生产柱状图

*@version1.0

*@since

*/

@SuppressWarnings("serial")

publicclassPillarServletextendsHttpServlet{

@Override

protectedvoidservice(HttpServletRequestrequest,

HttpServletResponseresponse)throwsServletException,IOException{

response.setContentType("text/html");

//使用普通数据集

DefaultCategoryDatasetchartDate=newDefaultCategoryDataset();

//增加测试数据,第一个参数是访问量,最后一个是时间,中间是显示用不考虑

chartDate.addValue(55,"访问量","-01");

chartDate.addValue(65,"访问量","-02");

chartDate.addValue(59,"访问量","-03");

chartDate.addValue(156,"访问量","-04");

chartDate.addValue(452,"访问量","-05");

chartDate.addValue(359,"访问量","-06");

try{

//从数据库中获得数据集

DefaultCategoryDatasetdata=chartDate;

//使用ChartFactory创建3D柱状图,不想使用3D,直接使用createBarChart

JFreeChartchart=ChartFactory.createBarChart3D(

"网站月访问量统计",//图表标题

"时间",//目录轴的显示标签

"访问量",//数值轴的显示标签

data,//数据集

PlotOrientation.VERTICAL,//图表方向,此处为垂直方向

//PlotOrientation.HORIZONTAL,//图表方向,此处为水平方向

true,//是否显示图例

true,//是否生成工具

false//是否生成URL链接

);

//设置整个图片的背景色

chart.setBackgroundPaint(Color.PINK);

//设置图片有边框

chart.setBorderVisible(true);

Fontkfont=newFont("宋体",Font.PLAIN,12);//底部

FonttitleFont=newFont("宋体",Font.BOLD,25);//图片标题

//图片标题

chart.setTitle(newTextTitle(chart.getTitle().getText(),titleFont));

//底部

chart.getLegend().setItemFont(kfont);

//得到坐标设置字体解决乱码

CategoryPlotcategoryplot=(CategoryPlot)chart.getPlot();

categoryplot.setDomainGridlinesVisible(true);

categoryplot.setRangeCrosshairVisible(true);

categoryplot.setRangeCrosshairPaint(Color.blue);

NumberAxisnumberaxis=(NumberAxis)categoryplot.getRangeAxis();

numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

BarRendererbarrenderer=(BarRenderer)categoryplot.getRenderer();

barrenderer.setBaseItemLabelFont(newFont("宋体",Font.PLAIN,12));

barrenderer.setSeriesItemLabelFont(1,newFont("宋体",Font.PLAIN,12));

CategoryAxisdomainAxis=categoryplot.getDomainAxis();

/*------设置X轴坐标上的文字-----------*/

domainAxis.setTickLabelFont(newFont("sans-serif",Font.PLAIN,11));

/*------设置X轴的标题文字------------*/

domainAxis.setLabelFont(newFont("宋体",Font.PLAIN,12));

/*------设置Y轴坐标上的文字-----------*/

numberaxis.setTickLabelFont(newFont("sans-serif",Font.PLAIN,12));

/*------设置Y轴的标题文字------------*/

numberaxis.setLabelFont(newFont("宋体",Font.PLAIN,12));

/*------这句代码解决了底部汉字乱码的问题-----------*/

chart.getLegend().setItemFont(newFont("宋体",Font.PLAIN,12));

//生成图片并输出

ChartUtilities.writeChartAsJPEG(response.getOutputStream(),1.0f,

chart,500,300,null);

}catch(Exceptione){

e.printStackTrace();

}

}

}

2、生成饼状统计图:

/**

*生成饼状统计图

*@version1.0

*@since

*/

@SuppressWarnings("serial")

publicclassCakeServletextendsHttpServlet{

protectedvoidservice(HttpServletRequestrequest,

HttpServletResponseresponse)throwsServletException,IOException{

response.setContentType("text/html");

//默认数据类型

DefaultPieDatasetdataType=newDefaultPieDataset();

//数据参数内容,数量

dataType.setValue("IE6",156);

dataType.setValue("IE7",230);

dataType.setValue("IE8",45);

dataType.setValue("火狐",640);

dataType.setValue("谷歌",245);

try{

DefaultPieDatasetdata=dataType;

//生成普通饼状图除掉3D即可

//生产3D饼状图

PiePlot3Dplot=newPiePlot3D(data);

JFreeChartchart=newJFreeChart(

"用户使用的浏览器类型",//图形标题

JFreeChart.DEFAULT_TITLE_FONT,//标题字体

plot,//图标标题对象

true//是否显示图例

);

//设置整个图片的背景色

chart.setBackgroundPaint(Color.PINK);

//设置图片有边框

chart.setBorderVisible(true);

//配置字体

Fontkfont=newFont("宋体",Font.PLAIN,12);//底部

FonttitleFont=newFont("宋体",Font.BOLD,25);//图片标题

//图片标题

chart.setTitle(newTextTitle(chart.getTitle().getText(),titleFont));

//底部

chart.getLegend().setItemFont(kfont);

ChartUtilities.writeChartAsJPEG(response.getOutputStream(),1.0f,

chart,500,300,null);

}catch(Exceptione){

e.printStackTrace();

}

}

}

3、柱状分布统计图:

/**

*柱状分布统计图

*@version1.0

*@since

*/

@SuppressWarnings("serial")

publicclassParagraphsServletextendsHttpServlet{

protectedvoidservice(HttpServletRequestrequest,

HttpServletResponseresponse)throwsServletException,IOException{

response.setContentType("text/html");

DefaultCategoryDatasetdataTime=newDefaultCategoryDataset();

//这是一组数据

dataTime.addValue(52,"0-6","-1-1");

dataTime.addValue(86,"6-12","-1-1");

dataTime.addValue(126,"12-18","-1-1");

dataTime.addValue(42,"18-24","-1-1");

//这是一组数据

dataTime.addValue(452,"0-6","-1-2");

dataTime.addValue(96,"6-12","-1-2");

dataTime.addValue(254,"12-18","-1-2");

dataTime.addValue(126,"18-24","-1-2");

//这是一组数据

dataTime.addValue(256,"0-6","-1-3");

dataTime.addValue(86,"6-12","-1-3");

dataTime.addValue(365,"12-18","-1-3");

dataTime.addValue(24,"18-24","-1-3");

try{

DefaultCategoryDatasetdata=dataTime;

//使用ChartFactory创建3D柱状图,不想使用3D,直接使用createBarChart

JFreeChartchart=ChartFactory.createBarChart3D(

"网站时间段访问量统计",

"时间",

"访问量",

data,

PlotOrientation.VERTICAL,

true,

false,

false

);

//设置整个图片的背景色

chart.setBackgroundPaint(Color.PINK);

//设置图片有边框

chart.setBorderVisible(true);

Fontkfont=newFont("宋体",Font.PLAIN,12);//底部

FonttitleFont=newFont("宋体",Font.BOLD,25);//图片标题

//图片标题

chart.setTitle(newTextTitle(chart.getTitle().getText(),titleFont));

//底部

chart.getLegend().setItemFont(kfont);

//得到坐标设置字体解决乱码

CategoryPlotcategoryplot=(CategoryPlot)chart.getPlot();

categoryplot.setDomainGridlinesVisible(true);

categoryplot.setRangeCrosshairVisible(true);

categoryplot.setRangeCrosshairPaint(Color.blue);

NumberAxisnumberaxis=(NumberAxis)categoryplot.getRangeAxis();

numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

BarRendererbarrenderer=(BarRenderer)categoryplot.getRenderer();

barrenderer.setBaseItemLabelFont(newFont("宋体",Font.PLAIN,12));

barrenderer.setSeriesItemLabelFont(1,newFont("宋体",Font.PLAIN,12));

CategoryAxisdomainAxis=categoryplot.getDomainAxis();

/*------设置X轴坐标上的文字-----------*/

domainAxis.setTickLabelFont(newFont("sans-serif",Font.PLAIN,11));

/*------设置X轴的标题文字------------*/

domainAxis.setLabelFont(newFont("宋体",Font.PLAIN,12));

/*------设置Y轴坐标上的文字-----------*/

numberaxis.setTickLabelFont(newFont("sans-serif",Font.PLAIN,12));

/*------设置Y轴的标题文字------------*/

numberaxis.setLabelFont(newFont("宋体",Font.PLAIN,12));

/*------这句代码解决了底部汉字乱码的问题-----------*/

chart.getLegend().setItemFont(newFont("宋体",Font.PLAIN,12));

ChartUtilities.writeChartAsJPEG(response.getOutputStream(),1.0f,

chart,500,300,null);

}catch(Exceptiones){

es.printStackTrace();

}

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。