2013-04-05 62 views
0

這是我.xhtmlprimefaces線型圖不可見

<div id="detailed_div_graph" align="center"> 
      <p:lineChart id="linear" value="#{ChartBean.linearModel}" legendPosition="e" 
       title="Medical Data" minY="0" maxY="10" style="height:300px"/> 
     </div> 

這是我的ChartBean代碼:

public class ChartBean implements Serializable { 

private CartesianChartModel linearModel; 

public ChartBean() { 
    createLinearModel(); 
} 

public CartesianChartModel getLinearModel() { 
    return linearModel; 
} 

private void createLinearModel() { 
    linearModel = new CartesianChartModel(); 

    LineChartSeries series1 = new LineChartSeries(); 
    series1.setLabel("BP"); 

    series1.set(1, 2); 
    series1.set(2, 1); 
    series1.set(3, 3); 
    series1.set(4, 6); 
    series1.set(5, 8); 

    linearModel.addSeries(series1); 
} 

} 

這有什麼錯我的代碼?

回答

0

這裏假設這個構造函數會被調用。

public ChartBean() { 
    createLinearModel(); 
} 

Jsf有階段,你應該考慮到它們。

如果你想在第一稱爲你createLinearModel()方法剛過豆第一次初始化,你應該@PostConstruct註解註釋它

@PostConstruct 
private void createLinearModel(){ 
    ... 
}