primefaces图表将数据插入错误位置
我遇到了条形图组件的一些奇怪行为。 我正在尝试创建两个chartSeries,并将它们添加到CartesianChartModel中。图表系列包括月份和每个月的数字。但是由于某种原因,第二个循环的值被放在了错误的位置primefaces图表将数据插入错误位置,primefaces,Primefaces,我遇到了条形图组件的一些奇怪行为。 我正在尝试创建两个chartSeries,并将它们添加到CartesianChartModel中。图表系列包括月份和每个月的数字。但是由于某种原因,第二个循环的值被放在了错误的位置 CartesianChartModel categoryModel = new CartesianChartModel(); ChartSeries problems = new ChartSeries(); ChartSerie
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);
第二个是这个
13:20:08,345 INFO [STDOUT] Month : September
13:20:08,345 INFO [STDOUT] Month : Oktober
但我的图表是这样的:
为什么将10月和9月的值放在前两列中,以及如何解决此问题
注:如果我更改for循环的顺序,图表上只显示10月和9月的统计数据,它将跳过其他月份。我编写了一个难看但有效的解决方案:
public class ChartSeriesTable {
private final Set<String> cols = new TreeSet<String>();
private final Set<String> rows = new HashSet<String>();
private final Map<String, Number> data = new HashMap<String, Number>();
public void set(String col, String row, Number value) {
cols.add(col);
rows.add(row);
data.put(row + "." + col, value);
}
public void setup(CartesianChartModel model) {
for (String row : rows) {
ChartSeries serie = new ChartSeries();
serie.setLabel(row);
for (String col : cols) {
Number d = data.get(row + "." + col);
if (d == null) {
serie.set(col, 0);
}
else {
serie.set(col, d);
}
}
model.addSeries(serie);
}
}
}
13:20:08,345 INFO [STDOUT] Month : September
13:20:08,345 INFO [STDOUT] Month : Oktober
public class ChartSeriesTable {
private final Set<String> cols = new TreeSet<String>();
private final Set<String> rows = new HashSet<String>();
private final Map<String, Number> data = new HashMap<String, Number>();
public void set(String col, String row, Number value) {
cols.add(col);
rows.add(row);
data.put(row + "." + col, value);
}
public void setup(CartesianChartModel model) {
for (String row : rows) {
ChartSeries serie = new ChartSeries();
serie.setLabel(row);
for (String col : cols) {
Number d = data.get(row + "." + col);
if (d == null) {
serie.set(col, 0);
}
else {
serie.set(col, d);
}
}
model.addSeries(serie);
}
}
}
ChartSeriesTable table = new ChartSeriesTable();
table.add("2001", "Girls", 30);
table.add("2001", "Boys", 20);
table.add("2002", "Boys", 15);
table.add("2003", "Boys", 10);
table.add("2004", "Girls", 40);
CartesianChartModel model = new CartesianChartModel();
table.setup(model);