我正在尝试使用PrimeFaces <p:chart>
标记在JSF页面上绘制图表:
<p:chart type="line" model="#{chartViewBean.lineModel}" style="width:400px;height:300px"/>
这是我的createLineModel
方法:
private void createLineModel() {
lineModel = new LineChartModel();
LineChartSeries series = new LineChartSeries();
for (ReportTotal reportTotal : reportBean.getReportTotals()) {
series.set(reportTotal.getDate(), reportTotal.getTotal());
System.out.println(reportTotal.getDate());
}
lineModel.addSeries(series);
lineModel.setTitle("Orders total");
lineModel.setAnimate(true);
lineModel.getAxis(AxisType.Y).setLabel("Values");
DateAxis axis = new DateAxis("Dates");
axis.setTickFormat("%b %#d, %y");
axis.setMax("2016-12-31");
lineModel.getAxes().put(AxisType.X, axis);
}
但是当我将硬编码数据设置为系列时:
series.set("2016-01-12", 65);
series.set("2016-03-18", 74);
series.set("2016-06-24", 24);
series.set("2016-11-30", 51);
当我输出System.out.println(reportTotal.getDate());
时,我也获得了与硬编码相同的数据:
2015-12-01
2015-12-02
2015-12-03
2015-12-04
2015-12-05
我的系列设置出了什么问题?
答案 0 :(得分:2)
由于x轴指向String值,
series.set(reportTotal.getDate(), reportTotal.getTotal());
应改为
series.set(reportTotal.getDate().toString(), reportTotal.getTotal());