例如画出如下表所示的曲线图。
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 |
…… | …… |
//获得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;
}