Problema com gráfico PrimeFaces

6 respostas
D
Bom galera, o problema que tenho é que o gráfico não esta me exibindo as linhas ! Se algum puder ajudar ai agradeço .. Abraços ..
<p:panel header="Gráfico">
	<h:form id="formParam" rendered="#{empty analiseBean.qtdtotalboletos}">
		<h3>Defina o Período</h3>
		<h:panelGrid columns="5">
					
			<h:outputText value="Início: "/>
			<p:calendar size="12"
					pattern="dd/MM/yyyy"
					value="#{analiseBean.inicio}"/>
					
			<h:outputText value="Fim: "/>
			<p:calendar size="12"
					pattern="dd/MM/yyyy"
					value="#{analiseBean.fim}"/>
							
			<p:commandButton value="Gerar" action="#{analiseBean.geraranalise}" ajax="false"
							update="formDados"/>
											
		</h:panelGrid>
	</h:form>
			
	<h:form id="formDados">
		<p:lineChart id="linha" value="#{analiseBean.linearModel}" legendPosition="e"
			title="Boletos" minY="0" maxY="10" style="height:300px"
			rendered="#{not empty analiseBean.qtdtotalboletos}"/>
	</h:form>		
			
</p:panel>
private void createLinearModel() {
	linearModel = new CartesianChartModel();
	System.out.println("GRAFICO");
	LineChartSeries series1 = new LineChartSeries();
	series1.setLabel("Total Boletos");
	System.out.println(""+getQtdtotalboletos()+"| "+ getValortotalboletos());
	series1.set(getQtdtotalboletos(), getValortotalboletos());
		
		
	LineChartSeries series2 = new LineChartSeries();
	series2.setLabel("Total Vencidos");
	System.out.println(""+getQtdvencidos()+"| "+ getValorvencidos());
	series1.set(getQtdvencidos(), getValorvencidos());
		
	linearModel.addSeries(series1);
	linearModel.addSeries(series2);
}

6 Respostas

C

O erro deve estar aqui …

rendered="#{not empty analiseBean.qtdtotalboletos}"/>

O rendered deve ser booleano (true/false)

D

Então … O gráfico chega a ser exibido … porém vazio, sem as linhas …
Veja a imagem


B

Diego, vc verificou com o debug se realmente os gets “getQtdvencidos() e getValorvencidos()” estão trazendo algum valor!?

D

Sim, estão sim … e só pra confirmar eu dei um PrintLn e estão lá …

C

Fiz algumas modificações e testei com sucesso ....

Segue pra exemplo

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">

    <body>
         <h:form id="formPrincipal" prependId="false" ><!---->
             
             <p:growl id="grow" showDetail="true"/> 
             <p:panel header="Gráfico">
                    <h:form id="formDados">
                        <h:panelGrid columns="2">
                            <p:lineChart id="linha" value="#{analiseBean.linearModel}" legendPosition="e"
                                    title="Boletos" minY="0" maxY="50" style="height:300px"
                                    rendered="#{not empty analiseBean.qtdtotalboletos}"/>
                            <p:commandButton value="Gerar" action="#{analiseBean.gerarAnalise}" ajax="false"
                                                                    update="formDados"/>

                            </h:panelGrid>
                    </h:form>		

            </p:panel>
        </h:form>
    </body>
</html>
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.LineChartSeries;

@ManagedBean
@ViewScoped
public class AnaliseBean implements Serializable {

    private int qtdtotalboletos=0;
    private CartesianChartModel linearModel;

	public AnaliseBean() {
        createLinearModel();
	}

        
        
    public CartesianChartModel getLinearModel() {
        return linearModel;
    }

    private void createLinearModel() {
	linearModel = new CartesianChartModel();
	System.out.println("GRAFICO");
	LineChartSeries series1 = new LineChartSeries();
	series1.setLabel("Total Boletos");
	//System.out.println(""+getQtdtotalboletos()+"| "+ getValortotalboletos());
	series1.set(20, 10);
		
		
	LineChartSeries series2 = new LineChartSeries();
	series2.setLabel("Total Vencidos");
	//System.out.println(""+getQtdvencidos()+"| "+ getValorvencidos());
	series1.set(12, 6);
		
	linearModel.addSeries(series1);
	linearModel.addSeries(series2);
}
    
    public String gerarAnalise(){
        
        getLinearModel().getSeries().get(0).set(15, 15);
        getLinearModel().getSeries().get(1).set(5, 6);
        return "";
        
    }

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

        LineChartSeries series1 = new LineChartSeries();
        series1.setLabel("Series 1");

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

        LineChartSeries series2 = new LineChartSeries();
        series2.setLabel("Series 2");
        series2.setMarkerStyle("diamond");

        series2.set(1, 6);
        series2.set(2, 3);
        series2.set(3, 2);
        series2.set(4, 7);
        series2.set(5, 9);

        linearModel.addSeries(series1);
        linearModel.addSeries(series2);
    }*/

    /**
     * @return the qtdtotalboletos
     */
    public int getQtdtotalboletos() {
        return qtdtotalboletos;
    }

    /**
     * @param qtdtotalboletos the qtdtotalboletos to set
     */
    public void setQtdtotalboletos(int qtdtotalboletos) {
        this.qtdtotalboletos = qtdtotalboletos;
    }

  
}

Como o build_successful disse verificar os gets e se estão dentro do intervalo mínimo e máximo ...

Verifica se o Bean implementa a classe Serializable

J

Teria como demonstrar como traz as informações do banco e utiliza ela no grafico.

Criado 9 de abril de 2012
Ultima resposta 14 de dez. de 2012
Respostas 6
Participantes 4