备份
来源:互联网 发布:js数组的map方法 编辑:程序博客网 时间:2024/06/06 05:39
public static Dataset getDataSet(Script script,Chart javaChart, String type) { DatasetReader reader = javaChart.getReader(); String labelField = javaChart.getLabelField(); //x-axis data ArrayList plotData = javaChart.getPlotData(); //available data for specific dataset ArrayList fieldData = javaChart.getFieldData(); //y-axis data // initialize XYDataset fieldCollection. ArrayList<String> fields = new ArrayList<String>(); //different fields name ArrayList<XYSeries> series = null; // collection of data in the same field XYSeriesCollection xySeriesCollection = null; // collections of data in different fields int flag = 0;// flag is a mark for different type dataset. if(reader == null || labelField == null || plotData == null || plotData.isEmpty()){ return null; } // classify different diagram to different dataset if(type.equals("4")||type.equals("11")||type.equals("14") ||type.equals("15")||type.equals("16")){ dataset = new DefaultXYDataset(); series = new ArrayList<XYSeries>(); xySeriesCollection = new XYSeriesCollection(); flag = 2; } Dataset set = null; // the raw data try { set = reader.read(script, -1); } catch (Exception e1) { e1.printStackTrace(); return null; } for (int i = 0; i < set.getRowCount(); i++) { //check each row String legendField = ""; String field = ""; for (int k = 0; k < fieldData.size(); k++) { // if one row has more than one y-value, combine them if (!fieldData.isEmpty()) { legendField = (String) fieldData.get(k); field = (set.getValueAt(i, legendField) + field).toString(); } else { legendField = null; field = null; }// end if } // end for System.out.println("field = " + field); // count fields and record them if(!fields.contains(field) && flag == 2){ fields.add(field); XYSeries xyseries = new XYSeries(field); series.add(xyseries); } for (int j = 0; j < plotData.size(); j++) { String label = set.getValueAt(i, labelField) + ""; double val = 0.0; // get x,y data, change data type Object o = set.getValueAt(i,((PlotData) plotData.get(j)).getField()); if(o==null||o.getClass().toString().equals("class java.lang.String")) continue; Number n = (Number) o; val = n.doubleValue(); LabelValue testValue = new LabelValue(label, i); String label2 = testValue.toString(); // reassemble data which are in same field into XYDataset structure if(flag == 2){ try{ double x = Double.parseDouble(label2); int num = fields.indexOf(field); series.get(num).add(Double.parseDouble(label2), val); }catch(Exception e){ e.printStackTrace(); return error; } }else{ addValue(dataset, val, field + '-' + ((PlotData) plotData.get(j)).getField(),label2); }// end if System.out.println("the field is: " + ((PlotData) plotData.get(j)).getField()); System.out.println("the value is: " + val); System.out.println("the label is: " + label2); }// end for // get collections of data in different fields if(flag == 2){ Iterator iterator = series.iterator(); while(iterator.hasNext()){ xySeriesCollection.addSeries((XYSeries) iterator.next()); } // end while return xySeriesCollection; }else{ return dataset; } // end if }// end for}
0 0
- 备份
- 备份
- 备份
- 备份
- 备份
- 备份
- 备份
- 备份
- 备份
- 备份
- 备份
- 备份
- 备份
- 备份
- 备份
- 备份
- 备份
- 备份
- 0000000000
- 未分类--Windows API--GetTickCount
- ios xmpp开发应用后台模式接收聊天信息
- juqery权威指南学习笔记-1
- juqery权威指南学习笔记-1
- 备份
- 生命力最强的新闻,放到二十年后依旧是新闻
- (转)IOS自定义UITabBar
- IOS开发实用工具
- 网络编程学习_简单的多进程并发服务器/客户端
- Windows多线程编程(7)--原子操作
- hdu 3487 Play with Chain(Splay)
- NYOJ 658 字符串右移
- 浅谈oracle中重建索引