我到是做过,就是方法麻烦些,用贴图的方式,用JSP计算出结果,用HTML贴图,还有计算一下贴图的方式和贴图的样式。

解决方案 »

  1.   

    学习 不会
    但是听说有个包 JFreeChart和Cewolf可以生产很多图表
    sourceforge.net有
      

  2.   

    用jfreechart来做了!
    很方便的!各种图表都可以做!
    根据数据变化
      

  3.   

    请问galewithwing(漂流的风):jfreechart在java类库中哪个包,能详细详细说一下吗?我找不到。
      

  4.   

    使用servlet绘制,然后显示出来,我就是这样实现的:)
      

  5.   

    柱状图,很好用的,如果你想使用曲线图,稍加修改即可/*
     * Created on 2004-6-22
     *
     * To change the template for this generated file go to
     * Window - Preferences - Java - Code Generation - Code and Comments
     */
    package neumed;//import HttpServlet;
    import java.io.*;
    import java.util.StringTokenizer;
    import javax.servlet.*;
    import javax.servlet.http.HttpServlet;//import com.sun.image.codec.jpeg.*; 
    import com.sun.image.codec.jpeg.*; 
    import java.awt.*; 
    import java.awt.image.*; //import org.jfree.data.*;
    //import org.jfree.chart.*;
    //import org.jfree.chart.plot.*;
    import Acme.JPM.Encoders.*;  //gif
    /**
     * @author Administrator
     *<pre>
     * To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Generation - Code and Comments
     * http://172.16.7.10/ImageServlet?itempce=5,5&unit=万&itemtitle=h23232323232323z测试测试&itemname=name,yali&width=400&height=400</pre>
     */
    public class ImageServlet extends HttpServlet {
    int Len;
    int leftMargine=50;
    int rightMargine=20;
    int topMargine=60;
    int buttomMargine=35;
    int width,height,w,h;
    int minStickLength=3;  //坐标的短刻度
    int majStickLength=8;   //坐标的长刻度
    int minStick=10;
    int majStick;
    String title;
    String xCode[],xName[];
    float yData[],xPce[];
    String MaxPce;
    boolean Mouse_Move;
    int x0,y0,X,Y,hx,hy;
    int degree=1;
    String unit="";
    //Label label[]=new Label[3];
    boolean mouse_move=false;

    private void init(ServletRequest req,int width,int height) {
    w=width-leftMargine-rightMargine;
    h=height-topMargine-buttomMargine;
    Color bc=new Color(229,229,229);
    try{
    title=util.iso2gb(req.getParameter("itemtitle"));
    unit=util.iso2gb(req.getParameter("unit"));
    }
    catch(Exception e){
    //System.out.println("Param title error!");    System.out.println(e);
    }
    try{
    xName=Subicode(util.iso2gb(req.getParameter("itemname")));
    //System.out.println(xName.length);       System.out.println(xName[1]);
    }
    catch(Exception e){
    //System.out.println("Param itemname error!");    System.out.println(e);
    }
    try{
    xPce=Substr(util.iso2gb(req.getParameter("itempce")));
    Len=xPce.length;
    hx=w/Len-5;
    MaxPce=getMaxVal(xPce);
    majStick=Integer.parseInt(MaxPce.substring(0,1))+2; //取最大pce的最大整数
    String ff;
    StringTokenizer st = new StringTokenizer(MaxPce, ".");
    degree=1;
    if (st.hasMoreTokens()){
    ff=st.nextToken();
    for(int d=1;d<ff.length();d++){
    degree=degree*10;
    }
    }
    }
    catch(Exception e){
    //System.out.println("Param itempce error!");    System.out.println(e);
    }
    }
    /**
     * @param req ,res  处理Http请求
     * <pre>
     * width  图像输出宽度
     * height 图像输出高度
     * Gif_Jpg gif 输出Gif图像;其他 输出jpg图像
     * itemtitle 图像标题
     * unit  纵坐标单元
     * itemname  所有项目的名称列表,以','分隔 【注:,前后不能有空格,否则为BMP】
     * itempce   所有项目的数值字符串列表,以','分隔 【注:,前后不能有空格,否则为BMP】
     * 
     * http://172.16.7.10/ImageServlet?itempce=5,5&unit=万&itemtitle=人员&itemname=何明,耿亚丽&width=400&height=300
     * 
     * </pre>
     */
    public void service(ServletRequest req, ServletResponse res)
    throws ServletException, IOException 
    {
    int width=400;
    int height=300;
    String swidth=req.getParameter("width"); 
    String sheight=req.getParameter("height");
    try{
    width=Integer.parseInt(swidth);
    height=Integer.parseInt(sheight);
    }catch(Exception whe){
    }
    init(req,width,height);

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics g = image.getGraphics();
    g.setColor(Color.white);
    g.fillRect(0,0, width, height);
    g.setColor(Color.black);
    try{
    g.drawRect(leftMargine,topMargine-20,w,h+20); //矩形方框
    int x0,y0,x1,y1,dy;
    float dyf;
    int totalStick=(majStick-1)*minStick;
    x0=leftMargine;
    dyf=(float)h/((majStick-1)*minStick);  //如果为整型的话,刻度会相对低一些。
    g.setFont(new Font("新宋体",Font.PLAIN,12));
    g.drawString(unit,x0-35,height-buttomMargine+5);    //y轴刻度数字  单位
    /*for(int i=0;i<30;i++){
     g.drawLine(12,300-i*10,10,300-i*10);  //y轴刻度标
     g.drawString(String.valueOf(300-i*10),22,300-i*10+5);    
     }*/
    for(int I=1;I<=totalStick;I++){
    y0=height-buttomMargine-(int)(I*dyf);
    y1=y0;
    x1=x0-minStickLength;
    if(I%minStick==0){
    x1=x0-majStickLength;
    g.drawString(""+(((I)/minStick)*degree),x1-25,y0+5);    //y轴刻度数字
    }
    g.drawLine(x0,y0,x1,y1);  //y轴刻度标
    }                              
    Color pceCololr1=new Color(0,0,255);
    Color pceCololr2=new Color(255,0,0);
    for(int I=0;I<Len;I++){
    x0=leftMargine+I*hx;
    hy=(int)((xPce[I]*h)/((majStick-1)*degree));
    y0=height-buttomMargine-hy;
    Color pceCololr=new Color(153,0,153);
    g.setColor(pceCololr);
    g.drawString(String.valueOf(xPce[I]),x0+5*I+5,y0-5);//在柱状图上绘制%
    if(I%2==0){
    g.setColor(pceCololr1);
    g.drawString(xName[I],x0+5+5*I,y0+hy+15);
    }else{
    g.setColor(pceCololr2);
    g.drawString(xName[I],x0+5+5*I,y0+hy+30);
    }
    g.fillRect(x0+5*I+5,y0,hx,hy);  //绘制柱状图
    //System.out.println((x0+5*I+5) + " y0 "+ y0 +" hx "+hx + " hy "+hy );
    //g.fillRect(220,183,160,82);  //绘制柱状图
    }
    Color titleColor=new Color(0,0,0);
    g.setColor(titleColor);
    g.setFont(new Font("新宋体",Font.BOLD,20));
    g.drawString(title,50,25);
    }
    catch(Exception e){
    //System.out.println("sellhis paint error.");       System.out.println(e);
    }
    //getDataSet();
    String Gif_Jpg=req.getParameter("Gif_Jpg");
    if(Gif_Jpg!=null && Gif_Jpg.equals("gif")){
    res.setContentType("image/gif");
    ServletOutputStream out = res.getOutputStream();
    //JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    GifEncoder encoder=new GifEncoder(image,out);
    encoder.encode();
    //encoder.encode(image);
    out.close();

    }else{
    res.setContentType("image/jpeg");
    ServletOutputStream out = res.getOutputStream();
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);  
    encoder.encode(image);
    out.close();
    }
    }
    /** 
     * @param str  以','为分隔符的浮点字符串
     * @return float[] 用','分隔出的浮点数组
     */
    private static float[] Substr(String str){
    int I=0;
    StringTokenizer st = new StringTokenizer(str,",");
    int len=st.countTokens();
    float[] val=new float[len];
    while(st.hasMoreTokens()) {
    val[I]=(new Float(st.nextToken())).floatValue();
    I++;
    }
    return val;
    }
    /** 
     * @param str   以','为分隔符的字符串
     * @return String[] 用','分隔出的字符串数组
     */
    private static String[] Subicode(String str){
    int I=0;
    StringTokenizer st = new StringTokenizer(str,",");
    int len=st.countTokens();
    String[] val=new String[len];
    while(st.hasMoreTokens()) {
    val[I]=st.nextToken();
    //System.out.println(val[I]);
    I++;
    }
    return val;
    }

    /** 
     * @param Maxval  浮点数组
     * @return String 返回最大浮点数的字符串
     */
    private static String getMaxVal(float[] Maxval){
    int I;
    float result;
    result=Maxval[0];
    for(I=0;I<Maxval.length;I++){
    if(result<Maxval[I])
    result=Maxval[I];
    }
    return Float.toString(result);
    }

    }在web.xml 中增加 <servlet>
      <servlet-name>aaa/ImageServlet</servlet-name>
      <servlet-class>aaa/ImageServlet</servlet-class>
    </servlet>使用:
    <img src="/ImageServlet?Gif_Jpg=gif&itemtitle=按客户统计&unit=元&width=1200&height=500&itempce=100,400,350&itemname=name1,name2,name3>
      

  6.   

    回复 yali(亚丽),虽然没用上,但还是谢谢你。