posts - 10,comments - 1,trackbacks - 0

柱状图的一个演示(不带热点提示的) index.jsp 往 barview.jsp 提交 index.jsp code:

<%@

page

 

language="java" pageEncoding="ISO-8859-1"%>

<

 

html>

<

 

head>

 

<title></title>

</

 

head>

<

 

body>

 

<form action="barview.jsp">

 

<input type="text" name="category">

 

<br>

 

<input type="submit" value="submit" />

 

<input type="reset" value="reset" />

 

</form>

</

 

body>

</

html>

 

html>

html>

 

 

 

barview.jsp code

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<%@

 

 

page language="java" contentType=

"text/html; charset=UTF-8"

 

 

 

pageEncoding="UTF-8"

%>

<%@

 

 

page

 

 

 

import="org.jfree.chart.ChartFactory,org.jfree.chart.JFreeChart,org.jfree.chart.plot.PlotOrientation,org.jfree.chart.servlet.ServletUtilities,org.jfree.data.category.*"

%>

<

 

 

html

>

 

 

<head

>

 

 

<title>jfreechart</TITLE

>

 

 

</HEAD

>

 

 

<body

>

 

 

<%

CategoryDataset dataset;

String category = request.getParameter(

 

"category"

);

category =

 

new String(category.getBytes("ISO8859_1"), "GBK"

);

 

 

if (category.equals("本科") || category.equals("高中"

)

|| category.equals(

 

"大专"

)) {

dataset = getDataSet();

}

 

else if (category.equals("硕士") || category.equals("博士"

)) {

dataset = getDataSet2();

}

 

else

{

dataset = getDataSet3();

}

String title = category +

 

"程序员在各城市薪金情况统计"

;

JFreeChart chart = ChartFactory.createBarChart3D(title,

 

"城市", "薪金"

,

dataset, PlotOrientation.VERTICAL,

 

true, false, false

);

String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300,

 

 

null

, session);

String graphURL = request.getContextPath()

+

 

"/servlet/DisplayChart?filename="

+ filename;

 

 

%>

 

 

<p ALIGN="CENTER"

>

 

 

<img src="<%=graphURL%>" width=500 height=300 border=

0

 

 

 

usemap="<%=filename%>"

>

 

 

</p

>

 

 

<%!private static

CategoryDataset getDataSet() {

DefaultCategoryDataset dataset =

 

new

DefaultCategoryDataset();

dataset.addValue(2000,

 

"北京", "VB"

);

dataset.addValue(1800,

 

"上海", "VB"

);

dataset.addValue(2200,

 

"广州", "VB"

);

dataset.addValue(3200,

 

"北京", "JAVA"

);

dataset.addValue(3500,

 

"上海", "JAVA"

);

dataset.addValue(3600,

 

"广州", "JAVA"

);

dataset.addValue(3300,

 

"北京", "DOT NET"

);

dataset.addValue(3400,

 

"上海", "DOT NET"

);

dataset.addValue(3700,

 

"广州", "DOT NET"

);

dataset.addValue(2500,

 

"北京", "DELPHI"

);

dataset.addValue(2800,

 

"上海", "DELPHI"

);

dataset.addValue(3200,

 

"广州", "DELPHI"

);

dataset.addValue(5000,

 

"北京", "VC"

);

dataset.addValue(3500,

 

"上海", "VC"

);

dataset.addValue(4600,

 

"广州", "VC"

);

 

 

return

dataset;

}

 

 

 

private static

CategoryDataset getDataSet2() {

DefaultCategoryDataset dataset =

 

new

DefaultCategoryDataset();

dataset.addValue(2000,

 

"上海", "VB"

);

dataset.addValue(3000,

 

"北京", "JAVA"

);

dataset.addValue(3330,

 

"上海", "JAVA"

);

dataset.addValue(3500,

 

"广州", "JAVA"

);

dataset.addValue(3500,

 

"北京", "DOT NET"

);

dataset.addValue(4000,

 

"上海", "DOT NET"

);

dataset.addValue(4800,

 

"广州", "DOT NET"

);

dataset.addValue(2600,

 

"北京", "DELPHI"

);

dataset.addValue(2200,

 

"上海", "DELPHI"

);

dataset.addValue(4000,

 

"北京", "VC"

);

dataset.addValue(4000,

 

"上海", "VC"

);

dataset.addValue(4200,

 

"广州", "VC"

);

 

 

return

dataset;

}

 

 

 

private static

CategoryDataset getDataSet3() {

DefaultCategoryDataset dataset =

 

new

DefaultCategoryDataset();

dataset.addValue(2100,

 

"北京", "VB"

);

dataset.addValue(2200,

 

"上海", "VB"

);

dataset.addValue(2100,

 

"广州", "VB"

);

dataset.addValue(3000,

 

"北京", "JAVA"

);

dataset.addValue(3200,

 

"上海", "JAVA"

);

dataset.addValue(3600,

 

"广州", "JAVA"

);

dataset.addValue(4100,

 

"北京", "DOT NET"

);

dataset.addValue(4200,

 

"上海", "DOT NET"

);

dataset.addValue(4160,

 

"广州", "DOT NET"

);

dataset.addValue(2400,

 

"北京", "DELPHI"

);

dataset.addValue(2600,

 

"上海", "DELPHI"

);

dataset.addValue(2500,

 

"广州", "DELPHI"

);

dataset.addValue(5400,

 

"北京", "VC"

);

dataset.addValue(5000,

 

"上海", "VC"

);

dataset.addValue(5500,

 

"广州", "VC"

);

 

 

return

dataset;

}

 

%>

 

 

</body

>

</

 

 

html

>



已有 0 人发表留言,猛击->>这里<<-参与讨论


JavaEye推荐




文章来源:http://java-jun.javaeye.com/blog/602594
posted on 2010-02-25 10:26 uqnetlove 阅读(101) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: