2014-11-19 2 views
0

Я создал круговую диаграмму в своем компоненте и добавлю ее в панель. Теперь я бы обновил эту диаграмму у компонента, но диаграмма не обновлена. Я обновил модель, и это правильно, но почему нет диаграммы?Обновление java created Chart Графики из Bean

Вот изображение, как это моя страница выглядит следующим образом: enter image description here

Когда я нажимаю кнопку, я бы обновить свой график.

Вот мой код, чтобы создать диаграмму:

Panel p = (Panel) e.getComponent().getParent().getParent(); 
p.setStyle("width: 500px; height: 400px !important;"); 

p.getChildren().clear(); 

Application ap = facesContext.getApplication(); 
Chart chart = (Chart) ap.createComponent(facesContext, "org.primefaces.component.Chart", 
     "org.primefaces.component.ChartRenderer"); 
chart.setId("chart" + chart.hashCode()); 

setTitle(p.getId(), msgs.get("dashboard_chart5_title")); 

if (getMemberTrendStatsIsNotEmpty()) { 
    HtmlForm form = (HtmlForm) ap.createComponent(HtmlForm.COMPONENT_TYPE); 
    form.setId("memberTrendForm"); 

    chart.setType("bar"); 
    chart.setId("memberTrend"); 
    chart.setModel(memberTrendStats); 
    ValueExpression ve = ap.getExpressionFactory().createValueExpression(facesContext.getELContext(), 
       "#{dashboardController.memberTrendStats}", PieChartModel.class); 
    chart.setValueExpression("model", ve); 
    form.getChildren().add(chart); 

    OutputLabel out = (OutputLabel) ap.createComponent(OutputLabel.COMPONENT_TYPE); 
    out.setFor("yearsBack"); 
    out.setValue(msgs.get("dashboard_chart1_search") + ": "); 
    form.getChildren().add(out); 

    InputText in = (InputText) ap.createComponent(InputText.COMPONENT_TYPE); 
    in.setId("yearsBack"); 
    in.setValue(yearsBack); 
    in.setStyle("margin-right:10px;"); 
    in.setType("number"); 

    NumberConverter nc = new NumberConverter(); 
    nc.setMaxFractionDigits(0); 
    in.setConverter(nc); 
    form.getChildren().add(in); 

    CommandButton btn = (CommandButton) ap.createComponent(CommandButton.COMPONENT_TYPE); 
    btn.setValue(msgs.get("dashboard_chart1_update")); 

    AjaxBehavior ab = new AjaxBehavior(); 
    ExpressionFactory ef = facesContext.getApplication().getExpressionFactory(); 
    MethodExpression me = ef.createMethodExpression(facesContext.getELContext(), 
     "#{dashboardController.updateMemberTrend}", 
     null, 
     new Class[] { ActionEvent.class }); 
    ab.setListener(me); 
    btn.addClientBehavior("submit", ab); 
    btn.setProcess("@form"); 
    btn.setAjax(true); 

    btn.addActionListener(new MethodExpressionActionListener(me)); 

    form.getChildren().add(btn); 

    p.getChildren().add(form); 
} else { 
    p.getChildren().add(getEmptyMessage()); 
} 

И вот мой код, чтобы обновить таблицу:

msgs = langFacade.getLangProperty(facesContext.getViewRoot().getLocale().getLanguage()); 

InputText in = (InputText) findUIComponent("memberTrendForm:yearsBack"); 

if (in != null) { 
    yearsBack = ((Long) in.getValue()).intValue(); 
} 

createChartModels(); 

RequestContext.getCurrentInstance().update("memberTrendForm:memberTrend"); 

Может кто-то помочь мне с этой проблемой? Thx

+0

Когда я нажмите F5 в браузере и выполнить представить график обновляется – Flagman

ответ

0

Окей, я нашел решение, я использовал ложные модели в выражении:

ValueExpression ve = ap.getExpressionFactory().createValueExpression(facesContext.getELContext(), 
       "#{dashboardController.memberTrendStats}", BarChartModel.class); 
chart.setValueExpression("model", ve); 
Смежные вопросы