当前位置: 技术问答>java相关
如何用JSP做出投票程序的饼状图
来源: 互联网 发布时间:2017-03-20
本文导语: JSP的投票程序中,饼状图例如何画,恳请指教 | 可以用applet来实现 用jsp把参数传进取 | 给你一个网址,你看看吧,可能有帮助 http://www.cn-java.com/target/news.php?news_id=723 | ...
JSP的投票程序中,饼状图例如何画,恳请指教
|
可以用applet来实现 用jsp把参数传进取
|
给你一个网址,你看看吧,可能有帮助
http://www.cn-java.com/target/news.php?news_id=723
http://www.cn-java.com/target/news.php?news_id=723
|
可以用javascript调用标准activex控件来作统计图。
|
你看一下http://sourceforge.net/上的项目cewolf,它是jfreechart在servlet/jsp上的应用
|
给你一段代码,直接能用
package thelearn;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
/**
*
*
*
*
* @author unascribed
* @version 1.0
*/
public class totalPie extends HttpServlet {
// static final private String CONTENT_TYPE = "text/html; charset=GBK";
static final private String CONTENT_TYPE = "image/jpeg";
String TitleArray[]={"第一季度","第二季度","第三季度","第四季度"};
int DataArray[]={120,100,60,200};
int Total=480;
//Initialize global variables
private java.awt.Component dummy;
public void init(ServletConfig conf) throws ServletException {
super.init(conf);
// dummy=new java.awt.Frame();
dummy=new java.awt.Frame();
dummy.addNotify();
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
response.setHeader("Pragma","no-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires",0);
java.awt.Color fg=java.awt.Color.black;
java.awt.Color bg=java.awt.Color.white;
java.awt.Color fill=new java.awt.Color(0xFBBFFF);
sendImage(response,createPieChart(200,200,fg,bg,fill));
/*
PrintWriter out = response.getWriter();
out.println("");
out.println("totalPie");
out.println("");
out.println("
out.println("");
*/
}
private java.awt.image.BufferedImage createPieChart(int w,int h,java.awt.Color fg,java.awt.Color bg,java.awt.Color fill)
{
int span=h+(DataArray.length+1)*20;
java.awt.image.BufferedImage img=createImage(w,span,bg);
java.awt.Graphics g=img.getGraphics();
//Draw segments start
int done=0;
int arc=0;
int tempHeight=0;
float percent;
String sPercent;
java.text.NumberFormat nf=java.text.NumberFormat.getPercentInstance();
for(int i=0;i1)
{
for(int i=0;i
package thelearn;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
/**
*
Title:
*
Description:
*
Copyright: Copyright (c) 2002
*
Company:
* @author unascribed
* @version 1.0
*/
public class totalPie extends HttpServlet {
// static final private String CONTENT_TYPE = "text/html; charset=GBK";
static final private String CONTENT_TYPE = "image/jpeg";
String TitleArray[]={"第一季度","第二季度","第三季度","第四季度"};
int DataArray[]={120,100,60,200};
int Total=480;
//Initialize global variables
private java.awt.Component dummy;
public void init(ServletConfig conf) throws ServletException {
super.init(conf);
// dummy=new java.awt.Frame();
dummy=new java.awt.Frame();
dummy.addNotify();
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
response.setHeader("Pragma","no-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires",0);
java.awt.Color fg=java.awt.Color.black;
java.awt.Color bg=java.awt.Color.white;
java.awt.Color fill=new java.awt.Color(0xFBBFFF);
sendImage(response,createPieChart(200,200,fg,bg,fill));
/*
PrintWriter out = response.getWriter();
out.println("");
out.println("totalPie");
out.println("");
out.println("
The servlet has received a GET. This is the reply.
");out.println("");
*/
}
private java.awt.image.BufferedImage createPieChart(int w,int h,java.awt.Color fg,java.awt.Color bg,java.awt.Color fill)
{
int span=h+(DataArray.length+1)*20;
java.awt.image.BufferedImage img=createImage(w,span,bg);
java.awt.Graphics g=img.getGraphics();
//Draw segments start
int done=0;
int arc=0;
int tempHeight=0;
float percent;
String sPercent;
java.text.NumberFormat nf=java.text.NumberFormat.getPercentInstance();
for(int i=0;i1)
{
for(int i=0;i