图表应用中缺失点的处理


例如画出如下表所示的曲线图。

00:00 1426
00:15 1408
00:30 1400
00:45 1390
01:00 1439
01:45 1203
02:00 1489
03:00 1456
03:15 1490
 …… ……

该图要求每隔5分钟一个点,但表中缺少很多时间的点。因此作图的时候要体现出空点来。

 

 1          //获得X轴的坐标 
 2 public static  String [] getAllLablesByfive(){
 3      String time[]=new String[24*12];
 4      String e="";
 5      for(int i=0;i<24;i++){
 6          e="";
 7          if(i<10){
 8              e="0";
 9          }    
10          for(int j=0;j<60;j++){
11              if (j%5 ==0){
12                   if(j<10){
13                        time[i*12+j/5]=e+i+":0"+j;
14                   }else{
15                        time[i*12+j/5]=e+i+":"+j;
16                   }
17              }
18                     
19          }         
20     }
21     return time;
22 }
23  //获取表格中的数据
24 public List<String[]> getDataAndTime(DefaultTableModel dtm, int  column){
25     List<String[]> list = new ArrayList<String[]>();
26     String[] str;
27     for(int i=0;i<dtm.getRowCount(); i++){
28         str = new String[2];
29         str[0] = dtm.getValueAt(i, 0).toString();
30         str[1] = dtm.getValueAt(i, column).toString();
31         list.add(str);
32     }
33     return list;
34 }
35 //处理Y轴的数据
36 public static double[] getDataViewerSetByDateOfFive(List<String[]> list,int len) throws Exception {
37     double[] res = getNoValueAry(len);  //此为chartDirector允许的空点的值
38     if (list != null && list.size() > 0) {
39         int i=0;
40         for(String [] o:list){
41            i=getCdqMinuteByfive(o[0],"HH:mm:ss")-1;
42            if(i<len&&MyUtils.isNumeric(o[1])){
43                res[i]=Double.parseDouble(o[1]);
44            }
45         }
46      }
47      return res;
48 }
49 //返回坐标
50 public static int getCdqMinuteByfive(String dateStr,String pattern)throws Exception{
51       int x=0;
52       SimpleDateFormat format = new SimpleDateFormat(pattern);
53       Date date = format.parse(dateStr);
54       Calendar calendar = new GregorianCalendar();
55       calendar.setTime(date);
56       x=calendar.get(Calendar.HOUR_OF_DAY)*12;
57       x=x+calendar.get(Calendar.MINUTE)/5+1;
58      return x;
59 }

 


 

posted @ 2013-06-03 17:27  薛遗山  阅读(268)  评论(0)    收藏  举报