呵呵,方法二。。推荐使用jfreechart,opensource的项目,不过它的文档是要买的。对于你的应用来看,可以使用它输出成OutputStream或者JPEG的方法,把图片放入jsp中

解决方案 »

  1.   

    rightman() 
    我download一个jfreechart,可是不会用,有没有介绍入门的资料?
      

  2.   

    用ChartDirector吧,是基于jfreechart开发的,使用起来要比jfreechart简单多了,http://www.advsofteng.com,里面有jspdemo的,看看就明白的
      

  3.   

    以下程序是用JavaBeans获取txt文件中的数据,然后用另一个JavaBeans生成jpeg图片,再用JSP显示出来。用这个程序改一下,应该可以实现你所要的效果吧。只要把获取txt文件数据的JavaBeans,改成获取数据库数据。想要得到什么效果的图,改一下生成jpeg图的JavaBeans就可以了吧!
    //生成图片的 Java Bean
    package chart;
    import java.io.*;
    import java.util.*;
    import com.sun.image.codec.jpeg.*;
    import java.awt.image.*;
    import java.awt.*;public class ChartGraphics {
      BufferedImage image;
      public void createImage(String fileLocation) {
        try {
          FileOutputStream fos = new FileOutputStream(fileLocation);
          BufferedOutputStream bos = new BufferedOutputStream(fos);
          JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
          encoder.encode(image);
          bos.close(); 
        } catch(Exception e) {
          System.out.println(e);
        }
      }  
      
      public void graphicsGeneration(int h1,int h2,int h3,int h4,int h5,int h6,int h7,int h8,int h9,int h10) {
      
        final int X=10;
        int imageWidth = 400;//图片的宽度
        int imageHeight = 500;//图片的高度   
        int columnWidth=30;//柱的宽度
        int columnHeight=400;//柱的最大高度
        
        ChartGraphics chartGraphics = new ChartGraphics();
        chartGraphics.image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); 
        Graphics graphics = chartGraphics.image.getGraphics();
        graphics.setColor(Color.white);
        graphics.fillRect(0,0,imageWidth,imageHeight);    
        graphics.setColor(Color.red);
        graphics.fillRect(X+1*columnWidth, columnHeight-h1, columnWidth, h1);
        graphics.setColor(Color.yellow);
        graphics.fillRect(X+2*columnWidth, columnHeight-h2, columnWidth, h2);
        graphics.setColor(Color.black);
        graphics.fillRect(X+3*columnWidth, columnHeight-h3, columnWidth, h3);
        graphics.setColor(Color.pink);    
        graphics.fillRect(X+4*columnWidth, columnHeight-h4, columnWidth, h4);
        graphics.setColor(Color.blue);
        graphics.fillRect(X+5*columnWidth, columnHeight-h5, columnWidth, h5);
        graphics.setColor(Color.red);
        graphics.fillRect(X+6*columnWidth, columnHeight-h6, columnWidth, h6);
        graphics.setColor(Color.orange);
        graphics.fillRect(X+7*columnWidth, columnHeight-h7, columnWidth, h7);
        graphics.setColor(Color.black);
        graphics.fillRect(X+8*columnWidth, columnHeight-h8, columnWidth, h8);
        graphics.setColor(Color.cyan);
        graphics.fillRect(X+9*columnWidth, columnHeight-h9, columnWidth, h9);
        graphics.setColor(Color.blue);
        graphics.fillRect(X+10*columnWidth, columnHeight-h10, columnWidth, h10);    
        chartGraphics.createImage("d:/test/chart/chart.jpg");
      } 
    }
    //读取Text文件中数据的 Java Bean
    package chart;
    import java.io.*;
    public class GetData {
      int heightArray[] = new int[10];
      public int[] getHightArray() {
        try {
          RandomAccessFile randomAccessFile = new RandomAccessFile ("d:/test/chart/ColumnHeightArray.txt","r");
          for (int i=0;i<10;i++)
          {
            heightArray[i] = Integer.parseInt(randomAccessFile.readLine());
          }  
        } 
        catch(Exception e) {
            System.out.println(e);
        }
        return heightArray;
      }
    }<%@ page import="chart.ChartGraphics" %>
    <%@ page import="chart.GetData" %>
    <jsp:useBean id="cg" class="chart.ChartGraphics"/>
    <jsp:useBean id="gd" class="chart.GetData"/>
    <%!
    int height[]=new int[10];
    %>
    <%
    height=gd.getHightArray();
    cg.graphicsGeneration(height[0],height[1],height[2],height[3],height[4],height[5],height[6],height[7],height[8],height[9]);
    %>
    <html>
    <body>
    <img src="../chart/chart.jpg"></img>
    </body>
    </html>
    数据文件ColumnHeightArray.txt
    150
    100
    250
    100
    220
    360
    190
    50
    200
    230
      

  4.   

    lihuileyou(辉) 
    非常感谢,不过我需要的是波形图,昨天晚上在csdn陶了很久,找到一个高手用js处理的,已经解决了,不过还是再次感谢!!!!!!