我正在尝试在PrimeFaces 3.5RC1中创建一个新图表,但出于某种原因,当所有数据都已收集并填充在图表中时,它不会显示在屏幕上。我知道Java代码没有任何问题,因为它正在运行,但图表是空白的。
请参阅下面的java和xhtml代码:
Java Bean:
public void searchMonthTotals() {
String sql = null;
if(retailID.equals("999") && billerID.equals("999")){
sql = "WITH CTE AS("
+ " SELECT Value,DAY(IntervalStartTime) AS DAY,MONTH(IntervalStartTime) AS MONTH,YEAR(IntervalStartTime) AS YEAR, "
+ " CASE WHEN MONTH(IntervalStartTime) = MONTH(GETDATE()) THEN 'Current' ELSE 'Previous' END AS Type "
+ " FROM tblpay@Stat s (nolock) "
+ " LEFT OUTER JOIN tblPay@StatConfig c (nolock) ON s.configId = c.id "
+ " LEFT OUTER JOIN tblpay@StatSlot l (nolock) ON s.slotId = l.id "
+ " WHERE IntervalStartTime >= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0) "
+ " AND IntervalEndTime <= DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0)) "
+ " AND s.configId = " + configID
+ " GROUP BY IntervalStartTime,value) "
+ " SELECT SUM(Value) AS Value, DAY,MONTH,YEAR,Type "
+ " FROM CTE "
+ " GROUP BY DAY,Type,MONTH,YEAR "
+ " ORDER BY Type ";
}else if(billerID.equals("999")){
sql = "WITH CTE AS("
+ " SELECT cm.Name AS Network,Value,DAY(IntervalStartTime) AS DAY,MONTH(IntervalStartTime) AS MONTH,YEAR(IntervalStartTime) AS YEAR, "
+ " CASE WHEN MONTH(IntervalStartTime) = MONTH(GETDATE()) THEN 'Current' ELSE 'Previous' END AS Type "
+ " FROM tblpay@Stat s (nolock) "
+ " LEFT OUTER JOIN tblPay@StatConfig c (nolock) ON s.configId = c.id "
+ " LEFT OUTER JOIN tblpay@StatSlot l (nolock) ON s.slotId = l.id "
+ " LEFT OUTER JOIN tblpay@company cm (nolock) ON s.networkId = cm.RecID "
+ " WHERE IntervalStartTime >= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0) "
+ " AND IntervalEndTime <= DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0)) "
+ " AND s.configId = " + configID
+ " AND s.networkId = " + retailID
+ " GROUP BY cm.Name,IntervalStartTime,value) "
+ " SELECT Network,SUM(Value) AS Value, DAY,MONTH,YEAR,Type "
+ " FROM CTE "
+ " GROUP BY Network,DAY,Type,MONTH,YEAR "
+ " ORDER BY Network,Type ";
}else if(retailID.equals("999")){
sql = "WITH CTE AS("
+ " SELECT cm.Name AS Biller,Value,DAY(IntervalStartTime) AS DAY,MONTH(IntervalStartTime) AS MONTH,YEAR(IntervalStartTime) AS YEAR, "
+ " CASE WHEN MONTH(IntervalStartTime) = MONTH(GETDATE()) THEN 'Current' ELSE 'Previous' END AS Type "
+ " FROM tblpay@Stat s (nolock) "
+ " LEFT OUTER JOIN tblPay@StatConfig c (nolock) ON s.configId = c.id "
+ " LEFT OUTER JOIN tblpay@StatSlot l (nolock) ON s.slotId = l.id "
+ " LEFT OUTER JOIN tblpay@company cm (nolock) ON s.issuerId = cm.RecID "
+ " WHERE IntervalStartTime >= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0) "
+ " AND IntervalEndTime <= DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0)) "
+ " AND s.configId = " + configID
+ " AND s.networkId = " + retailID
+ " GROUP BY cm.Name,IntervalStartTime,value) "
+ " SELECT Biller,SUM(Value) AS Value, DAY,MONTH,YEAR,Type "
+ " FROM CTE "
+ " GROUP BY Biller,DAY,Type,MONTH,YEAR "
+ " ORDER BY Biller,Type ";
}else{
sql = " WITH CTE AS( "
+ " SELECT cm.Name AS Network,co.Name AS Biller,DAY(IntervalStartTime) AS DAY,MONTH(IntervalStartTime) AS MONTH,YEAR(IntervalStartTime) AS YEAR, "
+ " CASE WHEN MONTH(IntervalStartTime) = MONTH(GETDATE()) THEN 'Current' ELSE 'Previous' END AS Type "
+ " FROM tblpay@Stat s (nolock) "
+ " LEFT OUTER JOIN tblPay@StatConfig c (nolock) ON s.configId = c.id "
+ " LEFT OUTER JOIN tblpay@StatSlot l (nolock) ON s.slotId = l.id "
+ " LEFT OUTER JOIN tblpay@company cm (nolock) ON s.networkId = cm.RecID "
+ " LEFT OUTER JOIN tblpay@company co (nolock) ON s.issuerId = co.RecID "
+ " WHERE IntervalStartTime >= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0) "
+ " AND IntervalEndTime <= DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0)) "
+ " AND s.configId = " + configID
+ " AND s.networkId = " + retailID
+ " AND s.issuerId = " + billerID
+ " GROUP BY IntervalStartTime,cm.Name,value,co.Name) "
+ " SELECT Network,Biller, SUM(Value) AS Value,DAY,MONTH,YEAR,Type "
+ " FROM CTE "
+ " GROUP BY Network,DAY,MONTH,YEAR,Type,Biller "
+ " ORDER BY Network,Type ";
}
try {
Connection con = db.getDBConnection(DatabaseTypes.TRANSACTION_DATABASE);
ResultSet rs = DatabaseHandler.executeQuery(con, sql);
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
maxTransactions = 0;
maxDays = 31;
boolean isEmpty = !rs.first();
if (!isEmpty) {
monthTotalsPrevious = new ArrayList<MonthlyGraphs>();
monthTotalsCurrent = new ArrayList<MonthlyGraphs>();
}
rs.beforeFirst();
while (rs.next()) {
MonthlyGraphs t = new MonthlyGraphs();
Calendar cal2 = Calendar.getInstance();
cal2.set(rs.getInt("YEAR"), rs.getInt("MONTH") - 1, rs.getInt("DAY"));
t.setDate(dateFormat.format(cal2.getTime()));
t.setTotalTransactions(rs.getInt("Value"));
t.setDay(rs.getInt("DAY"));
if (rs.getString("Type").equals("Current")) {
monthTotalsCurrent.add(t);
} else {
monthTotalsPrevious.add(t);
}
if (t.getTotalTransactions() > maxTransactions) {
maxTransactions = t.getTotalTransactions();
}
}
rs.close();
con.close();
createCategoryModel();
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "An error occurred.", e.getMessage()));
}
}
private void createCategoryModel() {
chartModel = new CartesianChartModel();
ChartSeries dailyTotalsPrevious = new ChartSeries();
dailyTotalsPrevious.setLabel("Previous");
for (int i = 0; i < monthTotalsPrevious.size(); i++) {
dailyTotalsPrevious.set(monthTotalsPrevious.get(i).getDay(), monthTotalsPrevious.get(i).getTotalTransactions());
}
chartModel.addSeries(dailyTotalsPrevious);
ChartSeries dailyTotalsCurrent = new ChartSeries();
dailyTotalsCurrent.setLabel("Current");
for (int i = 0; i < monthTotalsCurrent.size(); i++) {
dailyTotalsCurrent.set(monthTotalsCurrent.get(i).getDay(), monthTotalsCurrent.get(i).getTotalTransactions());
}
chartModel.addSeries(dailyTotalsCurrent);
}
xhtml页面:
<p:toolbar id ="graphtool">
<p:toolbarGroup align="left">
<h:panelGrid columns="6" cellpadding="5" >
<p:selectOneMenu id="billIssuerSelect" value="#{graphsBean.billerID}" style="width:250px" >
<f:selectItems value="#{generalBean.billIssuerList}" var="b" itemValue="#{b.billIssuerId}" itemLabel="#{b.billIssuerName}"/>
</p:selectOneMenu>
<p:selectOneMenu id="retailerSelect" value="#{graphsBean.retailID}" style="width: 250px" >
<f:selectItems value="#{generalBean.retailerList}" var="r" itemValue="#{r.retailerId}" itemLabel="#{r.retailerName}" />
</p:selectOneMenu>
<p:selectOneMenu id="configSelect" value="#{graphsBean.configID}" style="width: 250px" >
<f:selectItems value="#{graphsBean.configList}" var="r" itemValue="#{r.ID}" itemLabel="#{r.configName}" />
</p:selectOneMenu>
<p:commandButton id="refreshButton"
value="Generate"
icon="ui-icon-refresh"
update="graph"
ajax="true"
global="false"
actionListener="#{graphsBean.searchMonthTotals()}"/>
</h:panelGrid>
</p:toolbarGroup>
<p:toolbarGroup align="right">
<h:panelGrid columns="2" cellpadding="8" >
<h:commandLink>
<p:graphicImage style="border: none" value="../resources/excel24.png" />
<p:dataExporter type="xls" target="graph" fileName="Month Graph" />
</h:commandLink>
</h:panelGrid>
</p:toolbarGroup>
</p:toolbar>
<p:spacer width="10" height="10" />
<p:panel header="Month Graph">
<p:lineChart id="graph" value="#{graphsBean.chartModel}" style="width:500px;height:300px"
minY="0" maxY="#{graphsBean.maxTransactions}"
minX="1" maxX="#{graphsBean.maxDays}"
showMarkers="false"
legendPosition="n"
extender="customExtender"/>
</p:panel>
如果有人能指引我走向正确的方向那么好。
由于
答案 0 :(得分:0)
我解决了这个问题,xhtml页面中有一个Javascript代码需要包含在内才能生成图表。