当前位置: 技术问答>java相关
问:java实现图形化(线、饼、直方等)数据分析的方案?
来源: 互联网 发布时间:2015-07-27
本文导语: 由于工作的原因,需要用java来实现数据的相关分析,比如线图、饼图、直方图等等。要实现的要求是以浏览器(IE)为客户端,可以通过其方便的进行条件、图形选择,请问各位有什么较好的实现方案和案例?非常感谢...
由于工作的原因,需要用java来实现数据的相关分析,比如线图、饼图、直方图等等。要实现的要求是以浏览器(IE)为客户端,可以通过其方便的进行条件、图形选择,请问各位有什么较好的实现方案和案例?非常感谢!
|
下面的代码是用servlet生成一个jpeg,而后用jsp来显示
希望有帮助
servlet原代码:VoteImage.java :
/*
Author: Tony Wang
E-mail: lucky_tony@163.net
Date: 2001-01-01
如果对程序有什么疑问,可以和我联系,
另外程序如果有什么bug,麻烦指出!!
*/
import java.io.*;
import java.util.*;
import com.sun.image.codec.jpeg.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
public class VoteImage extends HttpServlet
{
private String strFile = null;
private Color color[]={Color.red,Color.black,Color.orange,
Color.green};
private int baseAng = 30;
public void doGet(HttpServletRequest request,HttpServletResponse
response)
throws ServletException,IOException
{
strFile = request.getRealPath("count.txt");
float[][] xy = new float[4][2];
xy = getNumAndPercent(strFile);
int[] ang = new int[4];
ang[0] = (int)(xy[0][1]*360);
ang[1] = (int)(xy[1][1]*360);
ang[2] = (int)(xy[2][1]*360);
ang[3] = 360-ang[0]-ang[1]-ang[2];
response.setHeader("Cache-Control","no-store");
response.setDateHeader("Expires",0);
response.setContentType("image/jpeg");
ServletOutputStream out=response.getOutputStream();
BufferedImage image=new BufferedImage(150,100,BufferedImage.
TYPE_INT_RGB);
Graphics2D g=(Graphics2D)image.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(Color.white);
g.fillRect(0,0,150,100);
AffineTransform at = null;
Arc2D arc = null;
int fromAng = baseAng;
at = AffineTransform.getRotateInstance((-20*java.lang.Math.PI)
/180,45,37);
g.setTransform(at);
int r =6;
int dx = (int)(r*java.lang.Math.cos((baseAng+ang[0])/2.0*java.
lang.Math.PI/180));
int dy = (int)(r*java.lang.Math.sin((baseAng+ang[0])/2.0*java.
lang.Math.PI/180));
arc = new Arc2D.Double(10+dx,24-dy,80,50,fromAng,ang[0],Arc2D.PIE);
g.setColor(color[0]);
g.fill(arc);
fromAng+=ang[0];
for (int i=1;i360)
{
fromAng-=360;
}
}
at = AffineTransform.getRotateInstance(0,arc.getCenterX(),arc.
getCenterY());
g.setTransform(at);
for (int i=0;i
希望有帮助
servlet原代码:VoteImage.java :
/*
Author: Tony Wang
E-mail: lucky_tony@163.net
Date: 2001-01-01
如果对程序有什么疑问,可以和我联系,
另外程序如果有什么bug,麻烦指出!!
*/
import java.io.*;
import java.util.*;
import com.sun.image.codec.jpeg.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
public class VoteImage extends HttpServlet
{
private String strFile = null;
private Color color[]={Color.red,Color.black,Color.orange,
Color.green};
private int baseAng = 30;
public void doGet(HttpServletRequest request,HttpServletResponse
response)
throws ServletException,IOException
{
strFile = request.getRealPath("count.txt");
float[][] xy = new float[4][2];
xy = getNumAndPercent(strFile);
int[] ang = new int[4];
ang[0] = (int)(xy[0][1]*360);
ang[1] = (int)(xy[1][1]*360);
ang[2] = (int)(xy[2][1]*360);
ang[3] = 360-ang[0]-ang[1]-ang[2];
response.setHeader("Cache-Control","no-store");
response.setDateHeader("Expires",0);
response.setContentType("image/jpeg");
ServletOutputStream out=response.getOutputStream();
BufferedImage image=new BufferedImage(150,100,BufferedImage.
TYPE_INT_RGB);
Graphics2D g=(Graphics2D)image.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(Color.white);
g.fillRect(0,0,150,100);
AffineTransform at = null;
Arc2D arc = null;
int fromAng = baseAng;
at = AffineTransform.getRotateInstance((-20*java.lang.Math.PI)
/180,45,37);
g.setTransform(at);
int r =6;
int dx = (int)(r*java.lang.Math.cos((baseAng+ang[0])/2.0*java.
lang.Math.PI/180));
int dy = (int)(r*java.lang.Math.sin((baseAng+ang[0])/2.0*java.
lang.Math.PI/180));
arc = new Arc2D.Double(10+dx,24-dy,80,50,fromAng,ang[0],Arc2D.PIE);
g.setColor(color[0]);
g.fill(arc);
fromAng+=ang[0];
for (int i=1;i360)
{
fromAng-=360;
}
}
at = AffineTransform.getRotateInstance(0,arc.getCenterX(),arc.
getCenterY());
g.setTransform(at);
for (int i=0;i