2016-07-19 22 views
1

我一直在PrimeFaces條形圖模型上工作,現在我的神經緊張起來,我無法弄清楚它的設置圖表系列值。期望的結果應該是One Open對於abc和一個關閉xyz,但它顯示一個開放和一個xyz關閉,ABC被忽略。如果我改變的p:圖表欄的ChartSeries不同步

barModel.addSeries(close); barModel.addSeries(open);

的位置

barModel.addSeries(open); barModel.addSeries(close);

話,就說明一個開放,一個封閉,只准ABC,不XYZ。

這裏是我的getBarModel()第一,

public BarChartModel getBarModel() { 

barModel=new BarChartModel(); 

    ChartSeries open = new ChartSeries(); 
    open.setLabel("OPEN"); 
    ChartSeries close = new ChartSeries(); 
    close.setLabel("Close"); 
open.set("abc", 1); 
    close.set("xyz", 1); 

    barModel.addSeries(close); 
    barModel.addSeries(open); 





     barModel.setMouseoverHighlight(false); 
     barModel.setShowPointLabels(false); 
     barModel.setTitle("Incident_application"); 
     barModel.setLegendPosition("ne"); 
     barModel.setShowDatatip(false); 
     barModel.setShowPointLabels(true); 
     barModel.setExtender("chartExtender"); 
     barModel.setSeriesColors("A2CC39,1B75BA"); 
     Axis xAxis = barModel.getAxis(AxisType.X); 
     xAxis.setLabel("Applications"); 
     barModel.setAnimate(true); 
     Axis yAxis = barModel.getAxis(AxisType.Y); 
     yAxis.setLabel("No. of Incident"); 
     yAxis.setMin(0); 
     yAxis.setMax(20); 
     yAxis.setTickInterval("10"); 

     return barModel; 
} 

,這裏是XHTML

<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" /> 
<h:outputScript library="primefaces" name="jquery/jquery-plugins.js" target="head" /> 

<style type="text/css"> 

table.jqplot-table-legend { 
border: none; 
font-size: x-large; 
} 
div.jqplot-table-legend-swatch 
{ 
width: 2vw; 
height: 2vh; 
} 
div.jqplot-gridData{ 
display:none; 
} 
div.jqplot-xaxis-tick{ 
font-weight:bold !important; 
} 
.jqplot-axis.jqplot-xaxis{ 
font-weight:bold; 
} 
.jqplot-point-label { 
font-size: 300%; 
color: black; 
font-weight: bold; 
} 
.jqplot-target{ 
color:black !important; 
} 

</style>  
<script> 

function chartExtender() {   

this.cfg.grid = {    
background: 'transparent', 
gridLineColor: '#303030', 
drawBorder: false, 
}; 


} 
</script> 
<h:form id="barChart"> 


<p:chart id="bar" type="bar" model="#{incidentBarChartController.barModel}" /> 


<p:poll interval="10" global="false" update="barChart"/> 

</h:form> 

</h:body> 

快照預期和實際結果的下方添加。

Expected Result

Actual Result

編輯 加入

open.set("abc", 1); 
     open.set("xyz",0); 
     close.set("xyz", 1); 
     close.set("abc", 0); 

後,我仍然會有奇怪的結果,即 1開和1關閉XYZ和0打開,0關閉XYZ。

+0

您需要爲每個密鑰的每個集合/系列賦予一個值。所以還要加上'open.set(「xyz」,0); close.set(「abc」,0);'(也許'null'起作用)。或者,也許這需要通過擴展程序在jqplot級別配置 – Kukeltje

+0

由於動態數據,這將過於複雜。 – Learner

+0

爲什麼?鑰匙是以這種或那種方式「訂購」的?或者是訂單相關?按照正確的順序在一組中組合鍵是唯一的「挑戰」。然後添加然後循環雖然該集合,並添加在其他集中的缺失的應該不難。 PF或jqPlot無法爲你解決這個問題。他們無法知道兩組中哪一組包含正確的順序。假設集合1以「a $#」開頭,​​集合2以「a#$」開頭,哪一個應該先到?根據「字符串」排序但是,如果你「xyz」應該在「abc」之前出現? – Kukeltje

回答

1

唯一的解決方法是,作爲開發人員,確保所有系列都包含所有密鑰並填充您沒有的密鑰,並確保所有系列中的所有密鑰都具有相同的順序。

原因是隻有您知道真正的訂單(這就是爲什麼LinkedHashMap在系列中使用)。 jQplot或PrimeFaces無法知道這一點。如果例如第一個系列沒有輸入密鑰,該系列被用作迭代的「主要」,缺失的密鑰將放在哪裏。如果例如在第6個位置,兩個人都有一個不在另一個集合中的鑰匙,哪一個鑰匙應該先取? jqPlot或PrimeFaces無法知道。作爲開發人員的所有原因應該通過在所有系列中放置所有密鑰來確保它是明確的。

+0

確切地說,這是唯一的情況。我會試一試,然後再回來。 – Learner