我有 3 个单独的对象,例如 GSMTable、SMSTable 和 GPRSTable。这些包括 2 个字段,称为 srDate 和 numberOfSR。现在我需要让它们成为一个 3D 数组对象,因为我需要为我的 jqPlot 折线图返回它,这是我的要求:
[
[gsmTable.srDate][gsmTable.noOfSR],
[smsTable.srDate][smsTable.noOfSR],
[gprsTable.srDate][gprsTable.noOfSR]
]
我编写了自己的代码,如下所示,但我无法完成它。
@RequestMapping(value = "/allGridView", method = RequestMethod.GET)
public @ResponseBody
Object[] showLineChart(Map<String, Object> map, HttpServletRequest request,
HttpServletResponse response) {
List<GSMTable> gsmList = contactService.fin();
List<Date>gsmDateList=new ArrayList<Date>();
List<Integer>gsmCount=new ArrayList<Integer>();
Object[] gsmArray=new Object[2];
for (Iterator iterator =gsmList.iterator();iterator.hasNext();) {
GSMTable gsmTable=(GSMTable)iterator.next();
gsmDateList.add(gsmTable.getSRDate());
gsmCount.add(gsmTable.getNumberOfSR());
}
gsmArray[0]=gsmDateList.toArray(new Date[gsmDateList.size()]);
gsmArray[1]=gsmCount.toArray(new Integer[gsmCount.size()]);
//=====================================================================================
List<SMSTable> smsList = contactService.sms();
List<Date>smsDateList=new ArrayList<Date>();
List<Integer>smsCount=new ArrayList<Integer>();
Object[] smsArray=new Object[2];
for (Iterator iterator =smsList.iterator();iterator.hasNext();) {
SMSTable smsTable=(SMSTable)iterator.next();
smsDateList.add(smsTable.getSRDate());
smsCount.add(smsTable.getNumberOfSR());
}
smsArray[0]=smsDateList.toArray(new Date[smsDateList.size()]);
smsArray[1]=smsCount.toArray(new Integer[smsCount.size()]);
//=====================================================================================
List<GPRSTable> gprsList = contactService.gprs();
List<Date>gprsDateList=new ArrayList<Date>();
List<Integer>gprsCount=new ArrayList<Integer>();
Object[] gprsArray=new Object[2];
for (Iterator iterator =gprsList.iterator();iterator.hasNext();) {
GPRSTable gprsTable=(GPRSTable)iterator.next();
gprsDateList.add(gprsTable.getSRDate());
gprsCount.add(gprsTable.getNumberOfSR());
}
gprsArray[0]=gprsDateList.toArray(new Date[gprsDateList.size()]);
gprsArray[1]=gprsCount.toArray(new Integer[gprsCount.size()]);
Object[][][] finalArray;
//after that how to complete it ? ? ?
//need to return finalArray as 3D Object Array
return finalArray;
}
gsm数组:
[[2012-11-05,05],[2012-11-06,08],[2012-11-07,10],[2012-11-08,14],[2012-11-08,09]]
短信数组:
[[2012-11-05,02],[2012-11-06,03],[2012-11-07,04],[2012-11-08,04],[2012-11-08,03]]
gprs数组:
[[2012-11-05,04],[2012-11-06,07],[2012-11-07,08],[2012-11-08,04],[2012-11-08,07]]
我需要将 gsmArray、smsArray 和 gprsArray 合并为 3D 数组,那么我的期望数组应该是:
[[2012-11-05,05],[2012-11-06,08],[2012-11-07,10],[2012-11-08,14],[2012-11-08,09],[2012-11-05,02],[2012-11-06,03],[2012-11-07,04],[2012-11-08,04],[2012-11-08,03],[2012-11-05,04],[2012-11-06,07],[2012-11-07,08],[2012-11-08,04],[2012-11-08,07]]