Line graph does not render (p:lineChart)

Asked

Viewed 94 times

1

xhtml code

<!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:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

<h:head>
</h:head>
<h:body>
    <h:form id="form">
        <p:lineChart id="candidatosPesquisa" value="#{linhaBean.linhaModel}"
            legendPosition="e" title="Pesquisa Eleitoral" minY="0" maxY="100"
            style="height:500px;">
        </p:lineChart>
    </h:form>
</h:body>
</html>

java code

package graficopizza;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartSeries;

@SessionScoped
@ManagedBean(name="linhaBean")
public class LinhaBean {

    private CartesianChartModel linhaModel;

    public CartesianChartModel getLinhaModel() {
        return linhaModel;
    }

    public LinhaBean(){
        popularLinhaModel();
    }

    private void popularLinhaModel() {
        linhaModel = new CartesianChartModel();
        ChartSeries candidato1 = new ChartSeries();
        candidato1.setLabel("Candidato 1");
        candidato1.set("Pesquisa 1", 10);
        candidato1.set("Pesquisa 2", 20);
        candidato1.set("Pesquisa 3", 40);
        candidato1.set("Pesquisa 4", 50);

        ChartSeries candidato2 = new ChartSeries();
        candidato2.setLabel("Candidato 2");
        candidato2.set("Pesquisa 1", 15);
        candidato2.set("Pesquisa 2", 29);
        candidato2.set("Pesquisa 3", 12);
        candidato2.set("Pesquisa 4", 40);

        ChartSeries candidato3 = new ChartSeries();
        candidato3.setLabel("Candidato 3");
        candidato3.set("Pesquisa 1", 60);
        candidato3.set("Pesquisa 2", 70);
        candidato3.set("Pesquisa 3", 90);
        candidato3.set("Pesquisa 4", 10);


        linhaModel.addSeries(candidato1);
        linhaModel.addSeries(candidato2);
        linhaModel.addSeries(candidato3);
    }
}
  • From the code it’s not very clear what you’re looking to do, but if the idea is to plot a graph with a line for each candidate, you’re looking for a combination of LineChartSeries. Take a look in this example.

  • That’s exactly what you understood... Already replaced by Linechartseries and not solved no friend, vlw the attempt

  • Try to cut and paste the example I gave you, at least to identify if it is an encoding problem or configuration of libraries / classpath, etc.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.