1
我正在經歷一些條形圖組件的怪異行爲。 我想創建兩個ChartSeries並將它們添加到CartesianChartModel。圖表系列由月份和每月的數字組成。但由於某些原因,第二個循環的值被置於錯誤的位置。primefaces圖表插入數據到錯誤的地方
CartesianChartModel categoryModel = new CartesianChartModel();
ChartSeries problems = new ChartSeries();
ChartSeries incidents = new ChartSeries();
problems.setLabel("PM");
incidents.setLabel("IM");
List<MonthCountWrapper> monthCountList = //get data
List<MonthCountWrapper> monthCountListInc = //get data
for (MonthCountWrapper mcw : monthCountListInc) {
System.out.println("Month : " + mcw.getMonth());
incidents.set(mcw.getMonth(), mcw.getCount());
}
categoryModel.addSeries(incidents);
for (MonthCountWrapper mcw : monthCountList) {
System.out.println("Month : " + mcw.getMonth());
problems.set(mcw.getMonth(), mcw.getCount());
}
categoryModel.addSeries(problems);
view.setCategoryModel(categoryModel);
XHTML:
<p:barChart id="basic" value="#{statisticLateView.categoryModel}"
legendPosition="ne" diameter="600"
rendered="#{statisticLateView.categoryModel.series.size() != 0 and statisticLateView.showBarChart}"
min="0" max="150" showDataTip="true" />
第一個系統輸出產生這樣的:
13:20:08,345 INFO [STDOUT] Month : Januar
13:20:08,345 INFO [STDOUT] Month : Februar
13:20:08,345 INFO [STDOUT] Month : Marts
13:20:08,345 INFO [STDOUT] Month : April
13:20:08,345 INFO [STDOUT] Month : Maj
13:20:08,345 INFO [STDOUT] Month : Juni
13:20:08,345 INFO [STDOUT] Month : Juli
13:20:08,345 INFO [STDOUT] Month : August
13:20:08,345 INFO [STDOUT] Month : September
13:20:08,345 INFO [STDOUT] Month : Oktober
而第二本
13:20:08,345 INFO [STDOUT] Month : September
13:20:08,345 INFO [STDOUT] Month : Oktober
,但我的圖表看起來像這樣:
爲什麼十月份和九月份的數值都放在前兩列以及如何解決這個問題?
PS。如果我更改for循環的順序,那麼只有10月和Septemeber統計信息會出現在圖表上,並且會跳過其他幾個月。