kim_miao 发表于 2013-1-15 03:00:11

web三维图表的开发

1、三维散点图的生成   
JMathPlot可产生常用的二维和三维图表,其生成图表的步骤与JFreeChart类似,设置数据集,定制图表相关属性及输出图表。对于三维图表的数据集,是用三元组存储的。但这些图表多用在Java Application 环境中。而要想将生成的图输出到浏览器。主要借助于JFreeChart中的EncoderUtil.encode方法将产生的BufferedImage对象实例编码成字节流.将些字节流放入Response中输出到浏览器端。Public Class Scatter3DChart implements Serializable{public byte[] generateImageBytes() throws IOException {      double[][] dataset = new double;      for (int i = 0; i < 20; i++) {   //随机产生二十个0至1的数据点,            dataset = Math.random();            dataset = Math.random();            dataset = Math.random();      }      Plot3DPanel plotpanel = new Plot3DPanel();//生成三维散点图实例。      plotpanel.setAxeLabel(0, "X轴");//设置X轴名称,0代表X轴      plotpanel.setAxeLabel(1, "Y轴");//设置Y轴名称,1代表Y轴      plotpanel.setAxeLabel(2, "Z轴");//设置Z轴名称,2代表Z轴               plotpanel.addScatterPlot("data", dataset); //添加数据集,data代表图例名称            plotpanel.setBackground(Color.WHITE);//设置图片的背景色彩      BufferedImage bufferedImage = new BufferedImage(width,height,    BufferedImage.TYPE_INT_RGB);      Graphics2D g = bufferedImage.createGraphics();      plotpanel.plotCanvas.paint(g);      return EncoderUtil.encode(bufferedImage, ImageFormat.PNG);//将生成的内存图片编码成字节流。    }}
有了图片字节流,就可以借助于Response将图片数据输出到浏览器。以下是
OutputStream os = new BufferedOutputStream(response.getOutputStream());
os.write(out); //out 代表从以上generateImageBytes ()方法中获得的字节流
os.flush();
so.close();
生成的三维散点图如下:



参考文献:
JfreeChart项目主页: http://www.jfree.org
JmathPlot项目主页:http://jmathtools.sourceforge.net
页: [1]
查看完整版本: web三维图表的开发