图表应用中缺失点的处理

来源:互联网 发布:c语言英语单词 编辑:程序博客网 时间:2024/04/30 13:32


例如画出如下表所示的曲线图。00:00142600:15140800:30140000:45139001:00143901:45120302:00148903:00145603:151490 …………该图要求每隔5分钟一个点,但表中缺少很多时间的点。因此作图的时候要体现出空点来。

 //获得X轴的坐标 public static  String [] getAllLablesByfive(){     String time[]=new String[24*12];     String e="";     for(int i=0;i<24;i++){         e="";         if(i<10){             e="0";         }             for(int j=0;j<60;j++){             if (j%5 ==0){                  if(j<10){                       time[i*12+j/5]=e+i+":0"+j;                  }else{                       time[i*12+j/5]=e+i+":"+j;                  }             }                             }             }    return time;} //获取表格中的数据public List<String[]> getDataAndTime(DefaultTableModel dtm, int  column){    List<String[]> list = new ArrayList<String[]>();    String[] str;    for(int i=0;i<dtm.getRowCount(); i++){        str = new String[2];        str[0] = dtm.getValueAt(i, 0).toString();        str[1] = dtm.getValueAt(i, column).toString();        list.add(str);    }    return list;}//处理Y轴的数据public static double[] getDataViewerSetByDateOfFive(List<String[]> list,int len) throws Exception {    double[] res = getNoValueAry(len);  //此为chartDirector允许的空点的值    if (list != null && list.size() > 0) {        int i=0;        for(String [] o:list){           i=getCdqMinuteByfive(o[0],"HH:mm:ss")-1;           if(i<len&&MyUtils.isNumeric(o[1])){               res[i]=Double.parseDouble(o[1]);           }        }     }     return res;}//返回坐标public static int getCdqMinuteByfive(String dateStr,String pattern)throws Exception{      int x=0;      SimpleDateFormat format = new SimpleDateFormat(pattern);      Date date = format.parse(dateStr);      Calendar calendar = new GregorianCalendar();      calendar.setTime(date);      x=calendar.get(Calendar.HOUR_OF_DAY)*12;      x=x+calendar.get(Calendar.MINUTE)/5+1;     return x;}


原创粉丝点击