graph with database

Posted by Flip_novidade on Stack Overflow See other posts from Stack Overflow or by Flip_novidade
Published on 2012-11-27T10:45:33Z Indexed on 2012/11/27 11:04 UTC
Read the original article Hit count: 140

Filed under:

I need to make two graphs with data coming from the database. I do not know where I am going wrong. If someone can show me the correct way, or provide any examples. must be two graphs, a graph of a specific student another graph of all students

thank you

public class NotasBean {  
    private Notas notas;  
    private Notas selectedNotas;  
    private List<Notas> filtroNotass;  

    public Notas getNotas() {  
        return notas;  
    }  
    public void setNotas(Notas notas) {  
        this.notas = notas;  
    }  

    public Notas getSelectedNotas() {  
        return selectedNotas;  
    }  
    public void setSelectedNotas(Notas selectedNotas) {  
        this.selectedNotas = selectedNotas;  
    }  
    public List<Notas> getFiltroNotass() {  
        return filtroNotass;  
    }  
    public void setFiltroNotass(List<Notas> filtroNotass) {  
        this.filtroNotass = filtroNotass;  
    }  

    public void prepararAdicionarNotas(){  
        notas = new Notas();  
    }  

    public void adicionarNotas(){  
        dao.NotasDao obj_dao = new dao.NotasDao();  
        obj_dao.save(notas);  
    }  

} 



package dao;  

import java.sql.PreparedStatement;  
import java.sql.ResultSet;  
import java.sql.Statement;  
import java.util.ArrayList;  
import java.util.List;  

import javax.faces.application.FacesMessage;  
import javax.faces.context.FacesContext;  

import model.Aluno;  
import model.Notas;  
import model.Notas;  


public class NotasDao {  
    private Conexao obj_conexao;  

    public NotasDao() {  
        obj_conexao = new Conexao();  
    }  

    public List<Notas> list() {  
        List<Notas> array_registros = new ArrayList<Notas>();  
        try {  
            String sql = "Select alu_in_ra, dis_st_sigla, ald_fl_p1, ald_fl_p2, ald_fl_p3, ald_fl_trab1, ald_fl_trab2 from cad_aluno_disciplina";  
            Statement comando_sql = (Statement) obj_conexao.getConexao()  
                    .createStatement();  
            ResultSet obj_result = comando_sql.executeQuery(sql);  

            while (obj_result.next()) {  
                Notas obj_notas = new Notas();  

                obj_notas.setAlura(obj_result.getInt("alu_in_ra"));  
                obj_notas.setDiscsigla(obj_result.getString("dis_st_sigla"));  
                obj_notas.setP1(obj_result.getInt("ald_fl_p1"));  
                obj_notas.setP2(obj_result.getInt("ald_fl_p2"));  
                obj_notas.setP3(obj_result.getInt("ald_fl_p3"));  
                obj_notas.setTrb1(obj_result.getInt("ald_fl_trab1"));  
                obj_notas.setTrb2(obj_result.getInt("ald_fl_trab2"));  


                array_registros.add(obj_notas);  
            }  

        } catch (Exception e) {  
            System.out.println("Erro no select" + e.getMessage());  

        } finally {  
            obj_conexao.fecharConexao();  
        }  

        return array_registros;  
    }  


    public void select(Aluno obj_aluno){  
        FacesContext mensagem = FacesContext.getCurrentInstance();  
        try{  
            String comando_sql = "Select alu_in_ra, dis_st_sigla, ald_fl_p1, ald_fl_p2, ald_fl_p3, ald_fl_trab1, ald_fl_trab2 from cad_aluno_disciplina where alu_in_ra=?";  
            PreparedStatement obj_sql = (PreparedStatement)  
                    obj_conexao.getConexao().prepareStatement(comando_sql);  

            obj_sql.setInt(1, obj_aluno.getRa());  

            obj_sql.executeUpdate();  
            mensagem.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Erro ao selecionar aluno!","Snif"));  

        }catch(Exception e){  
            mensagem.addMessage(null,   
                    new FacesMessage(FacesMessage.SEVERITY_FATAL, "Erro na inclusão: "+e.getMessage(),"  Ocoreu o erro: "+e.getMessage()));  
        }finally{  
            obj_conexao.fecharConexao();  
        }  
        return;  
    }  
}//fecha a classe 


package model;  

import java.io.Serializable;  

public class Notas implements Serializable{  
    private static final long serialVersionUID = 1L;  
    private int alura;  
    private String discsigla;  
    private float p1;  
    private float p2;  
    private float p3;  
    private float trb1;  
    private float trb2;  

    public Notas() {  

    } 



public Notas (int alura, String discsigla, float p1, float p2, float p3, float trb1, float trb2){  
    super();  
    this.alura=alura;  
    this.discsigla=discsigla;  
    this.p1=p1;  
    this.p2=p2;  
    this.p3=p3;  
    this.trb1=trb1;  
    this.trb2=trb2;  

}  

public int getAlura() {  
    return alura;  
}  

public void setAlura(int alura) {  
    this.alura = alura;  
}  

public String getDiscsigla() {  
    return discsigla;  
}  

public void setDiscsigla(String discsigla) {  
    this.discsigla = discsigla;  
}  

public float getP1() {  
    return p1;  
}  

public void setP1(float p1) {  
    this.p1 = p1;  
}  

public float getP2() {  
    return p2;  
}  

public void setP2(float p2) {  
    this.p2 = p2;  
}  

public float getP3() {  
    return p3;  
}  

public void setP3(float p3) {  
    this.p3 = p3;  
}  

public float getTrb1() {  
    return trb1;  
}  

public void setTrb1(float trb1) {  
    this.trb1 = trb1;  
}  

public float getTrb2() {  
    return trb2;  
}  

public void setTrb2(float trb2) {  
    this.trb2 = trb2;  
}  

}

<p:panel header="Grafico Notas Aluno" style="width: 550px">  
    <p:lineChart id="linear" value="#{notasDao.aluno.alura}" var="notas"  
        xfield="#{notas.alura}" height="300px" width="500px"  
        style="chartStyle">  
        <p:chartSeries label="Prova 1" value="#{notas.p1}" />  
        <p:chartSeries label="Prova 2" value="#{notas.p2}" />  
        <p:chartSeries label="Prova 3" value="#{notas.p3}" />  
        <p:chartSeries label="Trabalho 1" value="#{notas.trb1}" />  
        <p:chartSeries label="Trabalho 2" value="#{notas.trb2}" />  
    </p:lineChart>  
</p:panel> 


<p:panel header="Grafico Notas" style="width: 550px">  
    <p:lineChart id="linear" value="#{notasDao.natas}" var="notas"  
        xfield="#{notas.p1}" height="300px" width="500px"  
        style="chartStyle">  
        <p:chartSeries label="Prova 1" value="#{notas.p1}" />  
        <p:chartSeries label="Prova 2" value="#{notas.p2}" />  
        <p:chartSeries label="Prova 3" value="#{notas.p3}" />  
        <p:chartSeries label="Trabalho 1" value="#{notas.trb1}" />  
        <p:chartSeries label="Trabalho 2" value="#{notas.trb2}" />  
    </p:lineChart>  
</p:panel> 

© Stack Overflow or respective owner

Related posts about primefaces