我提交数据并显示了一个图表但是当我通过在表单中插入新值来提交它时,图表不会自行更新。我看到的另一件事是当我刷新页面时它会更新图表并使用新值获取图表展示。
例如,如果我给出值
Wheat=40和Sugar=60
并提交,它将显示图表。
现在,当我提交Wheat=90和Sugar=10时,它只显示页面上仍然存在的旧图表。
现在如果我刷新页面,更新值的图表将可用。
我怎样才能摆脱这个问题:(如果有人有,请提出解决方案。
这是我的代码
图表代码
<p:barChart id="horizontal"
value="#{reportingCharts.categoryModel}" legendPosition="se"
style="width:635px;height:500px" title="Horizontal Bar Chart"
orientation="horizontal" min="0" max="150" animate="true"
zoom="true" barMargin="90"
rendered="#{chartsRendering.barCharts}" showDatatip="true" shadow="true" />
按钮代码
<h:commandButton id="btnLanguage" action="#{reportingCharts.getGraphValuesOnLanguageBasis}"
value="Plot Chart Language">
</h:commandButton>
getGraphValuesOnLanbguageBasis 方法
public void getGraphValuesOnLanguageBasis() {
categoryModel = null;
resList = (ArrayList<ChartResult>) serviceObj
.getChartByLanguage(ranks, language);
if (chartType.equalsIgnoreCase("bar")
|| chartType.equalsIgnoreCase("line")
|| chartType.equalsIgnoreCase("column")) {
categoryModel = new CartesianChartModel();
ChartSeries langChart = null;
for (int a = 0; a < ranks.length; a++) {
langChart = new ChartSeries();
if(a == 0){
for(int z=0;z<language.length;z++){
langChart.set(languageMap.get(Integer.parseInt(language[z])),0);
}
}
String rank = "";
boolean rankAvailable = false;
for (int x = 0; x < resList.size(); x++) {
if(Integer.parseInt(resList.get(x).getRankId()) == Integer.parseInt(ranks[a])){
rank = resList.get(x).getRankName();
x = resList.size();
rankAvailable = true;
}
}
if(rankAvailable == false){
langChart.setLabel(rankMap.get(Integer.parseInt(ranks[a])));
}
else{
langChart.setLabel(rank);
}
for (int x = 0; x < resList.size(); x++) {
if (Integer.parseInt(resList.get(x).getRankId()) == Integer
.parseInt(ranks[a]) && rankAvailable == true) {
langChart.set(languageMap.get(Integer.parseInt(resList.get(x).getCriteria())), Integer
.parseInt(resList.get(x).getNoOfPersons()));
}
}
categoryModel.addSeries(langChart);
}
} else if (chartType.equalsIgnoreCase("pie")) {
pieModel = new PieChartModel();
for (int x = 0; x < resList.size(); x++) {
pieModel.set(languageMap.get(Integer.parseInt(resList.get(x).getCriteria())), Integer
.parseInt(resList.get(x).getNoOfPersons()));
}
}
ChartsRendering chartRenderer1 = (ChartsRendering) FacesContext
.getCurrentInstance().getExternalContext().getSessionMap()
.get("chartsRendering");
if (chartType.equalsIgnoreCase("bar")) {
chartRenderer1.showBarChart();
} else if (chartType.equalsIgnoreCase("line"))
chartRenderer1.showLineChart();
else if (chartType.equalsIgnoreCase("column"))
chartRenderer1.showColumnChart();
else if (chartType.equalsIgnoreCase("pie"))
chartRenderer1.showPieChart();
}