runtime Chart on dashboard

UI Components for JSF
Post Reply
Dário Apolinário
Posts: 2
Joined: 30 Mar 2011, 13:22

30 Mar 2011, 13:49

I need to create a chart programmatically and add it to a panel that will be displayed on a dashboard.

Currently i can can add panels dynamically to the dashboard, but when i add a Graph to a panel the following error happens.

Code: Select all

 INFO: Chart "TTTT:j_id7" has no ChartModel, declarative way of creating charts is deprecated, use a ChartModel instead. 


Code for chart creation

Code: Select all

 public void addGraphPanel(){
        FacesContext fc;
        Application application;
        fc = FacesContext.getCurrentInstance();
        application = fc.getApplication();

        LineChart graficoLineChart = (LineChart) application.createComponent(fc, "org.primefaces.component.chart.LineChart", "org.primefaces.component.chart.LineChartRenderer");
        graficoLineChart.setId("Linechart" + (new Date().getTime()));
        graficoLineChart.setHeight("260px");
        graficoLineChart.setWidth("310px");
        graficoLineChart.setWidgetVar(graficoLineChart.getId());

        CartesianChartModel cartesianModel = new CartesianChartModel();

             ChartSeries boys = new ChartSeries();
             boys.setLabel("Boys");

             boys.set("2004", 120);
             boys.set("2005", 100);
             boys.set("2006", 44);
             boys.set("2007", 150);
             boys.set("2008", 25);

             ChartSeries girls = new ChartSeries();
             girls.setLabel("Girls");

             girls.set("2004", 52);
             girls.set("2005", 60);
             girls.set("2006", 110);
             girls.set("2007", 135);
             girls.set("2008", 120);

          
             cartesianModel.addSeries(boys);
             cartesianModel.addSeries(girls);

        graficoLineChart.setModel(cartesianModel);

        

        Panel panel = (Panel) application.createComponent(fc, "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer");

        panel.setId("e" + (new Date()).getTime());
        panel.setHeader("EST" + (new Date()).getTime());
        panel.setClosable(true);
        panel.setToggleable(true);

        panel.getChildren().add(graficoLineChart);
        panelList.add(panel);

    }
dashborad binding

Code: Select all

 
<p:dashboard id="dboard"  widgetVar="dboard" binding="#{eSDashboard.dashboard2}">

</p:dashboard>
Can someone help me solving this issue.

Thanks in advance.

bitia
Posts: 2
Joined: 08 Feb 2011, 17:22

16 Jun 2011, 19:06

Hi, I did something similar, with dashboard and graphics.

I hope he still serves.

Dashboard.xhtml
reportesGraficos is a bean that contains my reports to graph which are registered in a database ...
reportxml is my class that returns me the values ??to be plotted, this is built dynamically reportesGraficos, I WAS eating JasperServer, Ireport.
rendered="#{reports.tipoGrafica==-1}" the name of the report is the type of chart you use, the rendered activates the corresponding I have two types because one is updated every 10 seconds and the other is not updated.

Code: Select all

<p:layoutUnit position="center" scrollable="true">
            <h:form>
                <p:dashboard id="board" model="#{dashboardBean.model}">
                    <c:forEach [color=#FF0000]items="#{dashboardBean.reportesGraficos}"[/color] var="reports">
                        <p:panel id="#{reports.nombreGenerico}" header="#{reports.nombreReporte}" toggleable="true" closable="true">
                            <p:pieChart value="#{reports.reportxml}" var="Rep"
                                        live="true" refreshInterval="3000"  
                                        categoryField="#{Rep.atributo}" dataField="#{Rep.elemento}" wmode="opaque" rendered="#{reports.tipoGrafica==-1}"/>

                            <p:pieChart value="#{reports.reportxml}" var="Rep"
                                        categoryField="#{Rep.atributo}" dataField="#{Rep.elemento}" wmode="opaque" rendered="#{reports.tipoGrafica==1}"/>

                            <p:lineChart value="#{reports.reportxml}" var="Rep" xfield="#{Rep.year}"
                                         live="true" refreshInterval="3000"
                                         wmode="opaque" rendered="#{reports.tipoGrafica==-2}">
                                <p:chartSeries label="Atributos" value="#{Rep.atributo}"  />
                                <p:chartSeries label="Elementos" value="#{Rep.elemento}" />
                            </p:lineChart>

                            <p:lineChart value="#{reports.reportxml}" var="Rep" xfield="#{Rep.year}"
                                         wmode="opaque" rendered="#{reports.tipoGrafica==2}">
                                <p:chartSeries label="Atributos" value="#{Rep.atributo}" />
                                <p:chartSeries label="Elementos" value="#{Rep.elemento}" />
                            </p:lineChart>

                            <p:barChart value="#{reports.reportxml}" var="Rep" yfield="#{Rep.year}"
                                        live="true" refreshInterval="3000"
                                        wmode="opaque" rendered="#{reports.tipoGrafica==-3}">
                                <p:chartSeries label="Atributo" value="#{Rep.atributo}" />
                                <p:chartSeries label="Elemento" value="#{Rep.elemento}" />
                            </p:barChart>

                            <p:barChart value="#{reports.reportxml}" var="Rep" yfield="#{Rep.year}"
                                        wmode="opaque" rendered="#{reports.tipoGrafica==3}">
                                <p:chartSeries label="Atributo" value="#{Rep.atributo}" />
                                <p:chartSeries label="Elemento" value="#{Rep.elemento}" />
                            </p:barChart>

                            <p:stackedBarChart value="#{reports.reportxml}" var="Rep" yfield="#{Rep.year}"
                                               live="true" refreshInterval="3000"
                                               wmode="opaque" rendered="#{reports.tipoGrafica==-4}">
                                <p:chartSeries label="Atributo" value="#{Rep.atributo}" />
                                <p:chartSeries label="Elemento" value="#{Rep.elemento}" />
                            </p:stackedBarChart>

                            <p:stackedBarChart value="#{reports.reportxml}" var="Rep" yfield="#{Rep.year}"
                                               wmode="opaque" rendered="#{reports.tipoGrafica==4}">
                                <p:chartSeries label="Atributo" value="#{Rep.atributo}" />
                                <p:chartSeries label="Elemento" value="#{Rep.elemento}" />
                            </p:stackedBarChart>

                            <p:columnChart value="#{reports.reportxml}" var="Rep" xfield="#{Rep.year}"
                                           live="true" refreshInterval="3000"
                                           wmode="opaque" rendered="#{reports.tipoGrafica==-5}">
                                <p:chartSeries label="Atributo" value="#{Rep.atributo}"/>
                                <p:chartSeries label="Elemento" value="#{Rep.elemento}"/>
                            </p:columnChart>

                            <p:columnChart value="#{reports.reportxml}" var="Rep" xfield="#{Rep.year}"
                                           wmode="opaque" rendered="#{reports.tipoGrafica==5}">
                                <p:chartSeries label="Atributo" value="#{Rep.atributo}"/>
                                <p:chartSeries label="Elemento" value="#{Rep.elemento}"/>
                            </p:columnChart>

                            <p:stackedColumnChart value="#{reports.reportxml}" var="Rep" xfield="#{Rep.year}"
                                                  live="true" refreshInterval="3000"
                                                  wmode="opaque" rendered="#{reports.tipoGrafica==-6}">
                                <p:chartSeries label="Atributo" value="#{Rep.atributo}" />
                                <p:chartSeries label="Elemento" value="#{Rep.elemento}" />
                            </p:stackedColumnChart>

                            <p:stackedColumnChart value="#{reports.reportxml}" var="Rep" xfield="#{Rep.year}"
                                                  wmode="opaque" rendered="#{reports.tipoGrafica==6}">
                                <p:chartSeries label="Atributo" value="#{Rep.atributo}" />
                                <p:chartSeries label="Elemento" value="#{Rep.elemento}" />
                            </p:stackedColumnChart>
                        </p:panel>
                    </c:forEach>
                </p:dashboard>
            </h:form>
        </p:layoutUnit>
DashboardBean.java

Code: Select all

@ManagedBean(name = "dashboardBean")
@RequestScoped
public class DashboardBean implements Serializable {

    private DashboardModel model;  
    private boolean _error = false;
    private List<ReportesGraficos> reportesGraficos;
    
    public DashboardBean() throws Exception {
        reportesGraficos = new ArrayList<ReportesGraficos>();
        generarReportes();

        model = new DefaultDashboardModel();
        DashboardColumn column1 = new DefaultDashboardColumn();
        DashboardColumn column2 = new DefaultDashboardColumn();
        DashboardColumn column3 = new DefaultDashboardColumn();
        DashboardColumn column4 = new DefaultDashboardColumn();

        for (int i = 0; i < reportesGraficos.size(); i++) {
            if (column1.getWidgetCount() < 2) {
                column1.addWidget(reportesGraficos.get(i).getNombreGenerico());
            } else {
                if (column2.getWidgetCount() < 2) {
                    column2.addWidget(reportesGraficos.get(i).getNombreGenerico());
                } else {
                    if (column3.getWidgetCount() < 4)
                    {
                        column3.addWidget(reportesGraficos.get(i).getNombreGenerico());
                    }
                    else
                    {
                        if(column4.getWidgetCount()<5)
                        {
                            column4.addWidget(reportesGraficos.get(i).getNombreGenerico());
                        }
                    }
                }
            }
        }
        model.addColumn(column1);
        model.addColumn(column2);
        model.addColumn(column3);
        model.addColumn(column4);
    }

    public List<ReportesGraficos> getReportesGraficos() {
        return reportesGraficos;
    }

    public void setReportesGraficos(List<ReportesGraficos> reportesGraficos) {
        this.reportesGraficos = reportesGraficos;
    }

    public boolean isError() {
        return _error;
    }

    public void setError(boolean _error) {
        this._error = _error;
    }

    

    public void handleReorder(DashboardReorderEvent event) {
        FacesMessage message = new FacesMessage();
        message.setSeverity(FacesMessage.SEVERITY_INFO);
        message.setSummary("Reordered: " + event.getWidgetId());
        message.setDetail("Item index: " + event.getItemIndex() + ", Column index: " + event.getColumnIndex() + ", Sender index: " + event.getSenderColumnIndex());
        addMessage(
                message);
    }

    public void handleClose(CloseEvent event) {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Panel Closed", "Closed panel id:'" + event.getComponent().getId() + "'");
        addMessage(
                message);
    }

    public void handleToggle(ToggleEvent event) {

        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, event.getComponent().getId() + " toggled", "Status:" + event.getVisibility().name());
        addMessage(
                message);
    }

    private void addMessage(FacesMessage message) {
        //FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);
        FacesContext.getCurrentInstance().addMessage(null, message);
    }

    public DashboardModel getModel() {
        return model;
    }

    public void ErrorShower(FacesMessage.Severity errorLevel, String errorMsg) {
        if (_error) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(errorLevel, errorMsg, ""));
            setError(
                    false);
        }
    }
}
http://imageshack.us/photo/my-images/4 ... zodx.png/

Netbeans 6.9
Primefaces 2.2
Glassfish 3.0
JasperServer 3.7
Ireport 3.7
My SQL Workbench 5.2

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 15 guests