以前在csdn上看到过。
以下是他的代码,希望有参考价值。<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.OutputStream, java.sql.*, java.awt.*, java.awt.geom.*, java.awt.image.BufferedImage, com.sun.image.codec.jpeg.*"%>
<%
////////////////////////////////////////////////////////////
// PieColors class manages the colors used in the pie chart
////////////////////////////////////////////////////////////
class PieColors{
Color pieColorArray[] = {
new Color(255,0,0), new Color(0,153,0), new Color(0,0,255),
new Color(0,255,0), new Color(255,0,255), new Color(255,204,0),
new Color(204,153,255), new Color(51,204,204), new Color(255,153,0),
new Color(255,102,0),
};
int curPieColor = 0;
public Color getPieColor(){
return pieColorArray[curPieColor];
}
public void setNewColor(){
curPieColor++;
if(curPieColor >= pieColorArray.length)
{curPieColor = 0;}
}
}
//get an array that contains the product names
String products[] = {"CT","X-ray","MRI","US","a","b","c","d"};
//read the data and store the totals in an array
float sales[] = {33,45,33,27,10,20,8,26};
float perc=0;
//Declare PieColors PieColors
PieColors pc = new PieColors();
//Colors Color
Color dropShadow = new Color(240,240,240);
//inner padding to make sure bars never touch the outer border
int innerOffset = 20;
//Set the graph's outer width & height
int WIDTH = 400;
int HEIGHT = 200;
int pieHeight = HEIGHT - (innerOffset * 2);
int pieWidth = pieHeight;
//To make a square (circular) pie
int halfWidth = WIDTH/2;
//Width of the inner graphable area
int innerWIDTH = WIDTH - (innerOffset * 2);
//graph dimensions Dimension
Dimension graphDim = new Dimension(WIDTH,HEIGHT);
Rectangle graphRect = new Rectangle(graphDim);
//border dimensions
Dimension borderDim = new Dimension(halfWidth-2,HEIGHT-2);
Rectangle borderRect = new Rectangle(borderDim);
/////////////////////////////////////////////////////////////
//Set up the graph
////////////////////////////////////////////////////////////
//Set content type
response.setContentType("image/gif");
//Create BufferedImage & Graphics2D
BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bi.createGraphics();
// Set Antialiasing RenderingHints
RenderingHints renderHints = new RenderingHints( RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHints(renderHints);
//Set graph background color to white:
g2d.setColor(Color.white);
g2d.fill(graphRect);
//Draw black border
g2d.setColor(Color.black);
borderRect.setLocation(1,1);
g2d.draw(borderRect);
//Now draw border for legend
borderRect.setLocation((WIDTH/2) + 1,1);
g2d.draw(borderRect);
////////////////////////////////////////////////////////////////////
//Draw data onto the graph:
////////////////////////////////////////////////////////////////////
int x_pie = innerOffset;
int y_pie = innerOffset;
int border = 0;
//Main chart Ellipse
//Ellipse2D.Double el = new Ellipse2D.Double(x_pie, y_pie, pieWidth, pieHeight);
Ellipse2D.Double elb = new Ellipse2D.Double(x_pie - border/2, y_pie - border/2, pieWidth + border, pieHeight + border);
//Shadow
g2d.setColor(dropShadow);
g2d.fill(elb);
//Border
g2d.setColor(Color.black);
g2d.draw(elb);
/////////////////////////////////////////////////////////////////
//Calculate the total sales
/////////////////////////////////////////////////////////////////
float salesTotal = 0.0f;
int lastElement = 0;
for(int i=0; i<products.length; i++)
{
if(sales[i] > 0.0f)
{
salesTotal += sales[i];
lastElement = i;
}
}
//////////////////////////////////////////////////////////////
//Draw the pie chart
/////////////////////////////////////////////////////////////
//Chart variables
int startAngle = 0;
//Legend variables
int legendWidth = 20;
int x_legendText = halfWidth + innerOffset/2 + legendWidth + 5;
int x_legendBar = halfWidth + innerOffset/2;
int textHeight = 20;
int curElement = 0;
int y_legend = 0;
//Dimensions of the legend bar
Dimension legendDim = new Dimension(legendWidth , textHeight/2);
Rectangle legendRect = new Rectangle(legendDim);
for(int i=0; i<products.length; i++)
{
if(sales[i] > 0.0f)
{
//Calculate percentage sales float
perc = (sales[i]/salesTotal);
//Calculate new angle
int sweepAngle = (int)(perc * 360);
//Check that the last element goes back to 0 position
if (i == lastElement)
{
sweepAngle = 360-startAngle;
}
// Draw Arc
g2d.setColor(pc.getPieColor());
g2d.fillArc(x_pie, y_pie, pieWidth, pieHeight, startAngle, sweepAngle);
//Increment startAngle with the sweepAngle
startAngle += sweepAngle;
/////////////
//Draw Legend
/////////////
//Set y position for bar
y_legend = curElement * textHeight + innerOffset;
//Display the current product
String display = products[i];
g2d.setColor(Color.black);
g2d.drawString(display, x_legendText, y_legend);
//Display the total sales
display = "" + (int)sales[i];
g2d.setColor(Color.black);
g2d.drawString(display, x_legendText + 80, y_legend);
//Display the sales percentage
display = " (" + (int)(perc*100) + "%)";
g2d.setColor(Color.red);
g2d.drawString(display, x_legendText + 110, y_legend);
//Draw the bar
g2d.setColor(pc.getPieColor());
legendRect.setLocation(x_legendBar,y_legend - textHeight/2);
g2d.fill(legendRect);
//Set new pie color
pc.setNewColor();
//Increment
curElement++;
}
}
////////////////////////////////////////////////
// Encode the graph
/////////////////////////////////////////
OutputStream output = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);
encoder.encode(bi);
output.close();
%>
以下是他的代码,希望有参考价值。<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.OutputStream, java.sql.*, java.awt.*, java.awt.geom.*, java.awt.image.BufferedImage, com.sun.image.codec.jpeg.*"%>
<%
////////////////////////////////////////////////////////////
// PieColors class manages the colors used in the pie chart
////////////////////////////////////////////////////////////
class PieColors{
Color pieColorArray[] = {
new Color(255,0,0), new Color(0,153,0), new Color(0,0,255),
new Color(0,255,0), new Color(255,0,255), new Color(255,204,0),
new Color(204,153,255), new Color(51,204,204), new Color(255,153,0),
new Color(255,102,0),
};
int curPieColor = 0;
public Color getPieColor(){
return pieColorArray[curPieColor];
}
public void setNewColor(){
curPieColor++;
if(curPieColor >= pieColorArray.length)
{curPieColor = 0;}
}
}
//get an array that contains the product names
String products[] = {"CT","X-ray","MRI","US","a","b","c","d"};
//read the data and store the totals in an array
float sales[] = {33,45,33,27,10,20,8,26};
float perc=0;
//Declare PieColors PieColors
PieColors pc = new PieColors();
//Colors Color
Color dropShadow = new Color(240,240,240);
//inner padding to make sure bars never touch the outer border
int innerOffset = 20;
//Set the graph's outer width & height
int WIDTH = 400;
int HEIGHT = 200;
int pieHeight = HEIGHT - (innerOffset * 2);
int pieWidth = pieHeight;
//To make a square (circular) pie
int halfWidth = WIDTH/2;
//Width of the inner graphable area
int innerWIDTH = WIDTH - (innerOffset * 2);
//graph dimensions Dimension
Dimension graphDim = new Dimension(WIDTH,HEIGHT);
Rectangle graphRect = new Rectangle(graphDim);
//border dimensions
Dimension borderDim = new Dimension(halfWidth-2,HEIGHT-2);
Rectangle borderRect = new Rectangle(borderDim);
/////////////////////////////////////////////////////////////
//Set up the graph
////////////////////////////////////////////////////////////
//Set content type
response.setContentType("image/gif");
//Create BufferedImage & Graphics2D
BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bi.createGraphics();
// Set Antialiasing RenderingHints
RenderingHints renderHints = new RenderingHints( RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHints(renderHints);
//Set graph background color to white:
g2d.setColor(Color.white);
g2d.fill(graphRect);
//Draw black border
g2d.setColor(Color.black);
borderRect.setLocation(1,1);
g2d.draw(borderRect);
//Now draw border for legend
borderRect.setLocation((WIDTH/2) + 1,1);
g2d.draw(borderRect);
////////////////////////////////////////////////////////////////////
//Draw data onto the graph:
////////////////////////////////////////////////////////////////////
int x_pie = innerOffset;
int y_pie = innerOffset;
int border = 0;
//Main chart Ellipse
//Ellipse2D.Double el = new Ellipse2D.Double(x_pie, y_pie, pieWidth, pieHeight);
Ellipse2D.Double elb = new Ellipse2D.Double(x_pie - border/2, y_pie - border/2, pieWidth + border, pieHeight + border);
//Shadow
g2d.setColor(dropShadow);
g2d.fill(elb);
//Border
g2d.setColor(Color.black);
g2d.draw(elb);
/////////////////////////////////////////////////////////////////
//Calculate the total sales
/////////////////////////////////////////////////////////////////
float salesTotal = 0.0f;
int lastElement = 0;
for(int i=0; i<products.length; i++)
{
if(sales[i] > 0.0f)
{
salesTotal += sales[i];
lastElement = i;
}
}
//////////////////////////////////////////////////////////////
//Draw the pie chart
/////////////////////////////////////////////////////////////
//Chart variables
int startAngle = 0;
//Legend variables
int legendWidth = 20;
int x_legendText = halfWidth + innerOffset/2 + legendWidth + 5;
int x_legendBar = halfWidth + innerOffset/2;
int textHeight = 20;
int curElement = 0;
int y_legend = 0;
//Dimensions of the legend bar
Dimension legendDim = new Dimension(legendWidth , textHeight/2);
Rectangle legendRect = new Rectangle(legendDim);
for(int i=0; i<products.length; i++)
{
if(sales[i] > 0.0f)
{
//Calculate percentage sales float
perc = (sales[i]/salesTotal);
//Calculate new angle
int sweepAngle = (int)(perc * 360);
//Check that the last element goes back to 0 position
if (i == lastElement)
{
sweepAngle = 360-startAngle;
}
// Draw Arc
g2d.setColor(pc.getPieColor());
g2d.fillArc(x_pie, y_pie, pieWidth, pieHeight, startAngle, sweepAngle);
//Increment startAngle with the sweepAngle
startAngle += sweepAngle;
/////////////
//Draw Legend
/////////////
//Set y position for bar
y_legend = curElement * textHeight + innerOffset;
//Display the current product
String display = products[i];
g2d.setColor(Color.black);
g2d.drawString(display, x_legendText, y_legend);
//Display the total sales
display = "" + (int)sales[i];
g2d.setColor(Color.black);
g2d.drawString(display, x_legendText + 80, y_legend);
//Display the sales percentage
display = " (" + (int)(perc*100) + "%)";
g2d.setColor(Color.red);
g2d.drawString(display, x_legendText + 110, y_legend);
//Draw the bar
g2d.setColor(pc.getPieColor());
legendRect.setLocation(x_legendBar,y_legend - textHeight/2);
g2d.fill(legendRect);
//Set new pie color
pc.setNewColor();
//Increment
curElement++;
}
}
////////////////////////////////////////////////
// Encode the graph
/////////////////////////////////////////
OutputStream output = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);
encoder.encode(bi);
output.close();
%>
解决方案 »
- 文本框选定
- tomcat 配置多域名时报400错误
- firefox下dwr回调函数不执行问题
- batch开发的基本技能到底指些什么????
- 我在JBuilder9下出现这样的错误信息:javax.servlet.jsp.JspException: Cannot find bean org.apache.struts.taglib.html.BEAN in scope
- 请问用JSP怎么实现成绩打印(输入查询条件后,从数据库中检索记录,导入Excel或者Word实现打印)急!!!
- 比较着急,多谢帮忙!JSP程序移植到LINUX下请问谁知道在LINUX下怎么样安装设置JDK和TOMCAT..
- 怎么能够拥有自己的JSP论坛呢
- 求助 HTTP Status 405 - HTTP method GET is not supported by this URL
- JSP页面报错:org.apache.jasper.JasperException
- 不知道这句错误提示是什么意思,大家帮帮忙看看
- preparedstatemend中如何处理in语法
如果需要更强大的功能,建议使用jFreechart,现在热的得都满天飞了
ChartFactory.createPie3DChart(chartName, pieDataset, true, false, false);
就可以了,很简单的,你只要得到生成图片的名字就可以了
DefaultPieDataset pieDataset = new DefaultPieDataset();
pieDataset.setValue(key, value);//用for循环设置你的值
//产生了一个chart对象,把它存为jpeg就好了
chart=ChartFactory.createPie3DChart(chartName, pieDataset, true, false, false);PiePlot plot = (PiePlot) chart.getPlot();
plot.setSectionLabelType(PiePlot.NAME_AND_PERCENT_LABELS);//设置显示的信息 plot.setNoDataMessage("No data available");//无数据时的信息ChartUtilities.saveChartAsJPEG(
new File(path+name),//你要保存图片的路径+文件名称
chart,//前面的chart对象
width,
height);
返回那个path+name就可以了
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.sun.image.codec.jpeg.*"%>
<%@ page import="java.awt.*"%>
<%@ page import="java.awt.geom.*"%>
<%@ page import="java.awt.image.*"%>
<%
response.setHeader("Cache-Control","no-store");
response.setDateHeader("Expires",0);
response.setContentType("image/jpeg");
OutputStream outImage=response.getOutputStream();
Color color[]={Color.red,Color.black,Color.orange,Color.green};
BufferedImage bufImage=new BufferedImage(150,100,BufferedImage.TYPE_INT_RGB);
Graphics2D g=(Graphics2D)bufImage.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(Color.white);
g.fillRect(0,0,150,100);
int iBaseAng=30;
int iElementCount,iShowType;
String strElementCount=request.getParameter("ElementCount");
String strShowType=request.getParameter("ShowType");
String strData=request.getParameter("Data");
if(strElementCount!=null)
{iElementCount=4;}
else
{iElementCount=4;}
if(strShowType!=null)
{iShowType=1;}
else
{iShowType=1;}
int[] Array_Ang=new int[iElementCount];
Array_Ang[0]=(int)(.35*360);
Array_Ang[1]=(int)(.15*360);
Array_Ang[2]=(int)(.25*360);
Array_Ang[3]=360-Array_Ang[0]-Array_Ang[1]-Array_Ang[2];
AffineTransform iAt=null;
Arc2D m_Arc=null;
int iFromAng=iBaseAng;
iAt=AffineTransform.getRotateInstance((-20*java.lang.Math.PI)/180,45,37);
g.setTransform(iAt);
switch(iShowType)
{
case 1:
int iR=6;
int iX=(int)(iR*java.lang.Math.cos((iBaseAng+Array_Ang[0])/2.0*java.lang.Math.PI/180));
int iY=(int)(iR*java.lang.Math.sin((iBaseAng+Array_Ang[0])/2.0*java.lang.Math.PI/180));
m_Arc=new Arc2D.Double(10+iX,24-iY,80,50,iFromAng,Array_Ang[0],Arc2D.PIE);
g.setColor(color[0]);
g.fill(m_Arc);
iFromAng+=Array_Ang[0];
for(int iIndex=1;iIndex<iElementCount;iIndex++)
{
g.setColor(color[iIndex]);
m_Arc=new Arc2D.Double(10,24,80,50,iFromAng,Array_Ang[iIndex],Arc2D.PIE);
g.fill(m_Arc);
iFromAng+=Array_Ang[iIndex];
if(iFromAng>360)
{
iFromAng-=360;
}
}
break;
case 2:
break;
default:
break;
}
iAt=AffineTransform.getRotateInstance(0,m_Arc.getCenterX(),m_Arc.getCenterY());
g.setTransform(iAt);
for(int jIndex=0;jIndex<iElementCount;jIndex++)
{
g.setColor(color[jIndex]);
g.fillRect(100,15*jIndex+20,10,10);
g.drawString("No."+jIndex,120,15*jIndex+20+8);
}
JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(outImage);
encoder.encode(bufImage);
outImage.close();
%>
ShowImage.jsp
<%@ page contentType="text/html; charset=gb2312"%>
<%@ include file="/DataIni/DataOpen.jsp"%>
<%@ include file="/ScriptLib/Init.jsp"%>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
<link rel="stylesheet" type="text/css" href="/StyleLib/Default_Style_Sheet.css"></head><body>
<%@ include file="/TemplateLib/Head.jsp"%>
<br>
<img src="/Test/Image.jsp?ElementCount=<%=4%>&ShowType=<%=1%>&Data=">
<%@ include file="/TemplateLib/Tail.jsp"%>
<%@ include file="/DataIni/DataClose.jsp"%>
</body></html>
http://blog.csdn.net/gjd111686/archive/2004/07/07/36245.aspx
<html xmlns:v="urn:schemas-microsoft-com:vml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
<style>v\:*{behavior:url(#default#vml)}/*声明v为vml变量*/</style>
</head><body onload="InitVRML();"><script>
//模拟数据
var RecordSetArray=new Array();
//模拟记录条数
var iRecordCount=20;
for(iIndex=0;iIndex<iRecordCount;iIndex++)
{
var UnitArray=new Array();
UnitArray[0]=iIndex;
UnitArray[1]=Math.round(Math.random()*1000);
RecordSetArray[iIndex]=UnitArray;
}
//模拟数据Y轴最大值[范围]
var iRecordMaxX=20;//模拟数据X轴最大值[范围]
var iRecordMaxY=1000;//模拟数据Y轴最大值[范围]
//坐标系统
var iScreenWidth=400;//真实宽度PX
var iScreenHeight=400;//真实高度PX
var iCoordSizeX=4000;//分隔宽度
var iCoordSizeY=4000;//分隔高度
var iCoordSizeStep=200;//坐标轴与边距
var iRectSize=100;//柱状图柱体宽度
var vGroup=null;//VRML区域
function Line(iRecordCount)
{
VRMLID.innerHTML="";
InitVRML();
CoordSize();
CoordSizeLine();
var iFromX=iCoordSizeStep;
var iFromY=0;
for(iIndex=0;iIndex<iRecordCount;iIndex++)
{
var vLine=document.createElement("v:line");
vLine.style.left="0";
vLine.style.top="0";
vLine.from="'"+iFromX+","+iFromY+"'";
iFromX=iCoordSizeStep+Math.round(RecordSetArray[iIndex][0]*(iCoordSizeX-iCoordSizeStep)/iRecordMaxX);
iFromY=Math.round(RecordSetArray[iIndex][1]*(iCoordSizeY-iCoordSizeStep)/iRecordMaxY);
vLine.to="'"+iFromX+","+iFromY+"'";
vLine.strokecolor="#000000";
vLine.strokeweight="1";
vLine.title="模拟数据第"+RecordSetArray[iIndex][0]+"条";
//var vStroke=document.createElement("v:stroke");
//vStroke.EndArrow="Classic";
//vStroke.StartArrow="Oval";
//vLine.appendChild(vStroke);
vGroup.appendChild(vLine);
}
}
function Circle(iRecordCount)
{
VRMLID.innerHTML="";
InitVRML();
var varMax=Math.pow(2,16)*360;
var vTotal=1;
var vStartAngle=0;
var vEndAngle=0;
var vPreAngle=0;
for(kIndex=0;kIndex<iRecordCount;kIndex++)
{
vTotal+=RecordSetArray[kIndex][1];
}
for(iIndex=0;iIndex<iRecordCount;iIndex++)
{
var vShape=document.createElement("v:shape");
vStartAngle+=vPreAngle;
vPreAngle=RecordSetArray[iIndex][1]/vTotal;
vEndAngle=RecordSetArray[iIndex][1]/vTotal; vShape.style.width=iCoordSizeX-2*iCoordSizeStep;
vShape.style.height=iCoordSizeY-2*iCoordSizeStep;
vShape.style.top=iCoordSizeStep;
vShape.style.left=iCoordSizeStep;
vShape.strokecolor="black";
vShape.fillcolor=RandColor(); vShape.path="M 2000 2000 AE 2000 2000 2000 2000 "+parseInt(varMax*vStartAngle)+" "+parseInt(varMax*vEndAngle)+" xe";
vShape.title="第"+RecordSetArray[iIndex][0]+"块";
vShape._scale=parseInt(360*(vStartAngle+vEndAngle/2));
vGroup.appendChild(vShape);
}
}
function Bar(iRecordCount)
{
VRMLID.innerHTML="";
InitVRML();
CoordSize();
CoordSizeLine();
var iStep=Math.round(iCoordSizeX/iRecordCount);
for(iIndex=1;iIndex<iRecordCount;iIndex++)
{
var iRnd=Math.round(Math.random()*(iCoordSizeY-iCoordSizeStep));
var vRect=document.createElement("v:rect");
vRect.style.left=iStep*iIndex;
vRect.style.top=(iCoordSizeY-iCoordSizeStep)-Math.round(RecordSetArray[iIndex][1]*(iCoordSizeY-iCoordSizeStep)/iRecordMaxY);
vRect.style.width=iRectSize;
vRect.style.height=Math.round(RecordSetArray[iIndex][1]*(iCoordSizeY-iCoordSizeStep)/iRecordMaxY);
vRect.fillColor="#EEEEEE";
vRect.title="模拟数据第"+RecordSetArray[iIndex][0]+"条的Y轴图示";
vGroup.appendChild(vRect);
}
}
function DrawLinesX(iMaxX,Object)
{
var iStep=Math.round(iCoordSizeX/iMaxX);
for(var iIndex=1;iIndex<=iMaxX;iIndex++)
{
var vLine=document.createElement("v:line");
vLine.from=iStep*iIndex+","+(iCoordSizeY-iCoordSizeStep);
vLine.to=iStep*iIndex+","+(iCoordSizeY-Math.round(iCoordSizeStep/2));
var vStroke=document.createElement("v:stroke");
vStroke.endArrow="Diamond";
vStroke.dashStyle="dot";
vLine.appendChild(vStroke);
Object.appendChild(vLine);
}
}
function DrawLinesY(iMaxY,Object)
{
var iStep=Math.round(iCoordSizeY/iMaxY);
for(var iIndex=0;iIndex<iMaxY;iIndex++)
{
var vLine=document.createElement("v:line");
vLine.from=iCoordSizeStep+","+iStep*iIndex;
vLine.to=Math.round(iCoordSizeStep/2)+","+iStep*iIndex;
var vStroke=document.createElement("v:stroke");
vStroke.endArrow="Diamond";
vStroke.dashStyle="dot";
vLine.appendChild(vStroke);
Object.appendChild(vLine);
}
}
function InitVRML()
{
VRMLID.innerHTML="";
vGroup=document.createElement("v:group");
vGroup.style.width=iScreenWidth+"px";
vGroup.style.height=iScreenHeight+"px";
vGroup.coordsize=iCoordSizeX+","+iCoordSizeY;
var vRect=document.createElement("v:rect");
vRect.style.width=iCoordSizeX+"px";
vRect.style.height=iCoordSizeY+"px";
vRect.fillColor="#FFFFFF";
vRect.strokeColor="#000000";
var vShadow=document.createElement("v:shadow");
vShadow.on="true";
vShadow.type="single";
vShadow.color="silver";
vShadow.offset="5pt,5pt";
vRect.appendChild(vShadow);
vGroup.appendChild(vRect); VRMLID.appendChild(vGroup);
}
function CoordSize()
{
var vLineX=document.createElement("v:line");
vLineX.from=iCoordSizeStep+","+iCoordSizeStep;
vLineX.to=iCoordSizeStep+","+(iCoordSizeY-iCoordSizeStep);
var vStrokeX=document.createElement("v:stroke");
vStrokeX.startArrow="classic";
vStrokeX.endArrow="oval";
vStrokeX.dashStyle="single";
vLineX.appendChild(vStrokeX);
vGroup.appendChild(vLineX); var vLineY=document.createElement("v:line");
vLineY.from=iCoordSizeStep+","+(iCoordSizeY-iCoordSizeStep);
vLineY.to=(iCoordSizeX-iCoordSizeStep)+","+(iCoordSizeY-iCoordSizeStep);
var vStrokeY=document.createElement("v:stroke");
vStrokeY.startArrow="oval";
vStrokeY.endArrow="classic";
vStrokeY.dashStyle="single";
vLineY.appendChild(vStrokeY);
vGroup.appendChild(vLineY);
}
function CoordSizeLine()
{
DrawLinesX(RecordSetArray.length,vGroup);
DrawLinesY(RecordSetArray.length,vGroup);
}
function RandColor()
{
return "rgb("+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+")";
}
function Zoom(iValue)
{
var varX=4000;
var varY=4000;
vGroup.coordsize=parseInt(varX/iValue)+","+parseInt(varY/iValue);
}
</script>
<center>
<input type="button" value="初始设置" onclick="InitVRML();">
<input type="button" value="柱状图" onclick="Bar(RecordSetArray.length);">
<input type="button" value="饼图" onclick="Circle(RecordSetArray.length);">
<input type="button" value="折线图" onclick="Line(RecordSetArray.length)">
<select onchange="Zoom(this.value)">
<option value="0.2" selected>20%</option>
<option value="0.25">25%</option>
<option value="0.4">40%</option>
<option value="0.5">50%</option>
<option value="0.75">75%</option>
<option value="0.8">80%</option>
<option value="1">原始大小</option>
<option value="1.25">125%</option>
<option value="1.5">150%</option>
<option value="2">200%</option>
<option value="3">300%</option>
<option value="4">400%</option>
</select>
<br>
<br>
<div id=VRMLID></div>
</center>
</body></html>
javax.servlet.ServletException
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.tb12_jsp._jspService(tb12_jsp.java:122)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
root cause java.lang.NoClassDefFoundError
org.jfree.chart.ChartFactory.createBarChart3D(ChartFactory.java:636)
org.apache.jsp.tb12_jsp._jspService(tb12_jsp.java:65)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
import java.awt.image.*;
import javax.imageio.*; //圖形輸出
//在內存中創建圖像
int width = 500, height = 240;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);//獲取圖像DC
Graphics g = image.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
g.setColor(Color.black);
Color[] clr={Color.red,Color.yellow,Color.blue,Color.cyan,Color.green,Color.orange,Color.magenta };int n=7;//數據的個數
int tmen[] = { 10, 20, 30, 40, 50, 60, 70}; //可以從數據取得數據
int summen=tmen[0] + tmen[1] + tmen[2] + tmen[3] + tmen[4] + tmen[5] + tmen[6];//求和;
int smen=0;
int sang=0; //起始角度
int curang=0; //角度的大小
for(i=0;i<n;i++){
smen=smen+tmen[i];
curang = tmen[i]* 360/summen ;
g.setColor(clr[i]);
//drawArc(xPos,yPos,width,height,startAngle,Angles);
//width,height是指在360度下整個弧的寬度和高度,如果相等,則表示一個圓,否則為橢圓
g.drawArc(20,20,200,200,sang,curang);
g.fillArc(20,20,200,200,sang,curang);
sang=smen*360/summen;
}g.dispose();//產生圖像
ImageIO.write(image, "JPEG", response.getOutputStream());//輸出到頁面