我有个朋友在炒股票,我看到那些趋势图挺好的,我想向各位高人请教一下,在JSP里可以做出来么?我刚学习JSP没多久,如果能做该如何实现啊?谢了啊!!!

解决方案 »

  1.   

    先学基础吧……不过那个好像Jasper Report可以做
      

  2.   

    gyl086 () 你好。
    我也很喜欢证券。我国目前最火的预测软件莫过于[指南针]了,最初的[指南针]是使用VB开发的。下面我向你推荐一种比较简单的方式:
    JSP调用JavaBean在网页上动态生成柱状图:   
        
      //Graphics.jsp   
      <jsp:useBean   id="cg"   scope="page"   class="tu.ChartGraphics"   />   
      <jsp:useBean   id="gd"   scope="page"   class="tu.GetData"   />   
      <%!   
      int   height[]=new   int[5];   
      %>   
        
      <%   
      height=gd.getHightArray();   
      cg.graphicsGeneration(height[0],height[1],height[2],height[3],height[4]);   
      %>   
        
      //ChartGraphics.java   
      package   tu;   
        
      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)   {   
        
        
      final   int   X=10;   
        
      int   imageWidth   =   300;//图片的宽度   
        
      int   imageHeight   =   300;//图片的高度     
        
      int   columnWidth=30;//柱的宽度   
        
      int   columnHeight=200;//柱的最大高度   
        
        
      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.drawRect(X+1*columnWidth,   columnHeight-h1,   columnWidth,   h1);   
        
      graphics.drawRect(X+2*columnWidth,   columnHeight-h2,   columnWidth,   h2);   
        
      graphics.drawRect(X+3*columnWidth,   columnHeight-h3,   columnWidth,   h3);     
        
      graphics.drawRect(X+4*columnWidth,   columnHeight-h4,   columnWidth,   h4);   
        
      graphics.drawRect(X+5*columnWidth,   columnHeight-h5,   columnWidth,   h5);     
        
      chartGraphics.createImage("c:\\jsp\\chart.jpg");   
        
      }     
        
      }   
        
      //GetData.java   
      //读取Text文件中数据的   Java   Bean   
      package   tu;   
        
      import   java.io.*;   
        
      public   class   GetData   {   
        
      int   heightArray[]   =   new   int[5];   
        
      public   int[]   getHightArray()   {   
        
      try   {   
        
      RandomAccessFile   randomAccessFile   =   new   RandomAccessFile   ("c:\\jsp\\ColumnHeightArray.txt","r");   
        
      for   (int   i=0;i<5;i++)   
        
      {   
        
      heightArray[i]   =   Integer.parseInt(randomAccessFile.readLine());   
        
      }     
        
      }     
        
      catch(Exception   e)   {   
        
      System.out.println(e);   
        
      }   
        
      return   heightArray;   
        
      }   
        
      }   
        
      //jsp/ColumnHeightArray.txt:   
      10   
      200   
      150   
      20   
      100
    最后奉劝一句,杀鸡最好不用牛刀。
      

  3.   

    hwak(忆天翔) 的方法正确,(虽然给出的例子很多东西都都写死了,根本不能重用)
        就是用Graphics Graphics2D等来画的,用起他的画图控件,会有很多问题,等它收费了,等它升级了,什么的,都是很大的问题,而要修改时,又是一个大问题, 兼容性,又是一个大问题.
      

  4.   

    jfreechart或者自己用 Graphics 画出来,也不难
      

  5.   

    jfreechart这类现成的东西就不错,功能很强.
      

  6.   

    MySoftZone() 这位大哥首先祝你春节愉快,谢谢在节日到来之际还能给小弟指点迷津,那么我想请教您几个问题,我现在也在努力用你说的这个方法来实现我想要的结果,并且基本上是出了结果了,但是如果我想在一个页面上显示多个图表怎么做呢?我现在用的是在一个页面上嵌入多个<iframe>的方法,但是这样的话只有最上面的一个<iframe>中的图显示是正确的,下面第二个开始的<iframe>的坐标就开始不对了.实际情况是每个<iframe>中代码都是一样的,只是添入的显示数据不同而已,为什么会出现坐标不对呢?
      

  7.   

    jfreechart不错
    ①设置数值
    ②设置图片样式
    ③生成图片
    三步搞定,当然里面有些具体的东西要你自己研究去
      

  8.   

    恩,好的,也非常感谢谢楼上这位朋友的指点,不过JSP我还不怎么会,呵呵,看来革命道路才开始第一步嘛,恩,祝所有帮助过我和即将也会帮助我的朋友们新年快乐,万事如意,才华更放光彩.
      

  9.   

    JFREECHART,也才开始学,大家一起努力学!