大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 程序开发 -> java绘制一个成交量的统计图

java绘制一个成交量的统计图

时间: 2021-07-31 作者:daque

在前方,我用多线程写了一个绘制了股票k线图的步调.这边我再经过绘制一个拍板量的统计图证明对鼠票事变的运用.这边咱们要传入几个参数:<applet code="sellhis.class" archive="sellhis.jar" width="640" height="400"><param name="itemmonth" value="200201"><param name="itemcode" value="00002,00014,00019,00023,00041,00102,00113,00114,00129,00132,00142,00146,00179,00203,00213,00223,00341"><param name="itemval" value="272950,193950,1015600,142700,1618500,671650,2453300,630150,28375,1827660,7700,75700,27375,3375600,47500,17500,17500"><param name="itempce" value="219,156,817,114,2302,540,1974,507,22,1471,6,60,22,4717,38,114,14"></applet>察看演练sellhis.java源步调如次:import java.awt.*;import java.applet.*;import java.awt.font.*;import java.awt.event.*;import java.io.*;import java.lang.*;import java.util.*;public class sellhis extends applet{  static int len;  int leftmargine=50;  int rightmargine=20;  int topmargine=80;  int buttommargine=20;  int width,height,w,h;  int minsticklength=3;  //坐目标短刻度  int majsticklength=8;   //坐目标长刻度  int minstick=10;  int majstick;  string title;  string xtitle="股票代碼";  string xcode[];  float ydata[],xpce[];  string maxpce;  boolean mouse_move;  int x0,y0,x,y,hx,hy;  label label[]=new label[3];  boolean mouse_move=false;  public void init() {    width=this.getbounds().width;    height=this.getbounds().height;    w=width-leftmargine-rightmargine;    h=height-topmargine-buttommargine;    setsize(width,height);    color bc=new color(229,229,229);    setbackground(bc);    setlayout(null);    for(int i=0;i<3;i++){      label[i]=new label();      label[i].setforeground(color.blue);      this.add(label[i]);      if(i==0)        label[i].reshape(75,topmargine-25,60,15);      if(i==1)        label[i].reshape(230,topmargine-25,80,15);      if(i==2)        label[i].reshape(505,topmargine-25,60,15);    }    try{      title=gettitle(getparameter("itemmonth"));    }    catch(exception e){      system.out.println("param itemmonth error!");   system.out.println(e); }    try{      xcode=subicode(getparameter("itemcode"));      len=xcode.length;      hx=w/len;    }    catch(exception e){      system.out.println("param itemcode error!");   system.out.println(e); }    try{      ydata=substr(getparameter("itemval"));    }    catch(exception e){      system.out.println("param itemval error!");   system.out.println(e); }    try{      xpce=substr(getparameter("itempce"));      maxpce=getmaxval(xpce);      majstick=integer.parseint(maxpce.substring(0,1))+2; //取最大pce的最大平头    }    catch(exception e){      system.out.println("param itempce error!");   system.out.println(e); }    try{      addmouselistener(new mouseadapter(){        public void mousereleased(mouseevent evt){//检验和测定开释鼠标按键事变          setcursor(cursor.getdefaultcursor());          point ioc=evt.getpoint();          x=ioc.x;         //把暂时座标传播给另一线程          y=ioc.y;          //repaint();        }      });   addmousemotionlistener(new mousemotionadapter(){        public void mousedragged(mouseevent evt){          point ioc=evt.getpoint();          if((ioc.x>leftmargine & ioc.x< w+leftmargine) & (ioc.y >topmargine & ioc.y< h+topmargine))            setcursor(cursor.getpredefinedcursor(cursor.hand_cursor));          else            setcursor(cursor.getdefaultcursor());        }        public void mousemoved(mouseevent evt){   //检验和测定鼠标挪动事变          point ioc=evt.getpoint();          x=ioc.x;          y=ioc.y;          graphics gten;          gten=getgraphics();          gten.setxormode(color.white);          gten.setcolor(color.blue);          int axsis;          if(ioc.x >leftmargine & ioc.x< w+leftmargine & ioc.y>topmargine & ioc.y<h+topmargine){            try{               axsis=(x-leftmargine)/hx;        //设定横座标范畴                //在以次地区内,把鼠标暂时横座标处的百般股票参数表露在相映的标签上                 label[0].settext(xcode[axsis]);                 label[1].settext(float.tostring(ydata[axsis]));                 float pcent=(xpce[axsis]/100);                 label[2].settext(float.tostring(pcent));            }            catch(exception err){            }            try{              if(y0 >topmargine & y0< h+topmargine)                gten.drawline(leftmargine,y0,w+leftmargine,y0);              if(y >topmargine & y< h+topmargine)                gten.drawline(leftmargine,y,w+leftmargine,y);              if(x0 >leftmargine & x0< w+leftmargine)                gten.drawline(x0,topmargine,x0,h+topmargine);              if(x >leftmargine & x< w+leftmargine)                gten.drawline(x,topmargine,x,h+topmargine);              x0=x;              y0=y;            }            finally{              gten.dispose();            }          }        }      }); } catch(exception e) {  system.out.println("sellhis construct add mouse listener error!");  system.out.println(e); }  }  public void paint(graphics g){    try{      g.drawstring("股票代碼:",20,topmargine-15);      g.drawstring("賣空拍板金額:",150,topmargine-15);      g.drawstring("賣空拍板金額占總賣空拍板金額%:",320,topmargine-15);      g.drawrect(leftmargine,topmargine,w,h); //矩形方框      int x0,y0,x1,y1,dy;      int totalstick=(majstick-1)*minstick;      x0=leftmargine;      dy=h/((majstick-1)*minstick);      for(int i=1;i<=totalstick;i++){        y0=height-buttommargine-i*dy;        y1=y0;        x1=x0-minsticklength;        if(i%minstick==0){          x1=x0-majsticklength;          g.drawstring(""+((i)/minstick)+"0%",x1-25,y0+5);    //y轴刻度数字        }        g.drawline(x0,y0,x1,y1);  //y轴刻度标      }      for(int i=0;i<len;i++){        x0=leftmargine+i*hx;        hy=(int)((xpce[i]/100)*(h/((majstick-1)*10)));        y0=height-buttommargine-hy;        float pcent=(xpce[i]/100);        color pcecololr=new color(153,0,153);        g.setcolor(pcecololr);        g.setfont(new font("times new roman",font.plain,11));        g.drawstring(float.tostring(pcent),x0,y0-5);//在柱状图上绘制%        if(i%2==0)          g.setcolor(color.orange);        else          g.setcolor(color.red);        g.fillrect(x0,y0,hx,hy);  //绘制柱状图        //g.setcolor(color.red);  //绘制股票代码        //g.setfont(new font("times new roman",font.plain,10));        //g.drawstring(""+xcode[i],x0,height-topmargine+40);      }      color titlecolor=new color(0,64,128);      g.setcolor(titlecolor);      g.setfont(new font("monospaced",font.bold,20));      g.drawstring(title,190,40);    }    catch(exception e){      system.out.println("sellhis paint error.");      system.out.println(e);    }  }  public 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]=integer.parseint(st.nexttoken());      i++;    }    return val;  }  public 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();      i++;    }    return val;  }  public 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);  }  public string gettitle(string str){    string title;    title=str.substring(0,4)+"年"+str.substring(4,6)+"月賣空股票統計";    return title;  }  public int getleftmargine(){    return leftmargine;  }  public int getbuttommargine(){    return buttommargine;  }  public void setleftmargine(int leftmargine){    this.leftmargine=leftmargine;  }  public void setbuttommargine(int buttommargine){    this.buttommargine=buttommargine;  }}

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.