Hey guys,
I'm trying to generate a bar chart using GoogleCharts but it's not showing anything. The pie chart appears smoothly but the bar chart does not.
Can anyone tell me what's wrong?
The function that creates it is MontaGraficoBarras(ByVal pLabel As WebControls.Label, ByVal pDados As String, ByVal pCodTipoCurso As Integer)
Here's the code:
Partial Class forms_Principal
Inherits System.Web.UI.Page
Private AnoLetivo As New CENTEC.objVestibularAno
Private Coligada As New CENTEC._objEducacional
Private Vestibular As New CENTEC.objVestibularCurso
Private CursoTurno As New CENTEC.objVestibularTurnos
Private Inscritos As New CENTEC.objVestibularInscricao
Private Sub MontaDashBoard(ByVal pLabel As WebControls.Label, ByVal pTitulo As String, ByVal pSubtitulo As String,
ByVal pTotalH As Integer, ByVal pSubTotalH As Integer,
ByVal pTotalM As Integer, ByVal pSubTotalM As Integer)
Dim pBoostrap As String
pBoostrap = "<div class='row'>" &
"<div class='col-sm-12'>" &
"<div style='background-color:#014573; color:#fff; text-align:center; padding:8px;'>" &
"<div style='font-size:24px; text-align:center; font-weight:bold;'>" & pTitulo & "</div>" &
"<div style='text-align:center;'>" & pSubtitulo & "</div>" &
"</div>" &
"</div>" &
"</div>" &
" " &
"<div class='row'>" &
"<div class='col-sm-4'>" &
"<div style='font-size:20px; text-align:center; font-weight:bold;'>Homens</div>" &
"<div style='font-size:20px; text-align:center;'>" & Format(pTotalH, "#,000") & "</div>" &
"<div style='text-align:center;'>(" & Format(pSubTotalH, "#,000") & ")</div>" &
"</div>" &
"<div class='col-sm-4'>" &
"<div style='font-size:20px; text-align:center; font-weight:bold;'>Mulheres</div>" &
"<div style='font-size:20px; text-align:center;'>" & Format(pTotalM, "#,000") & "</div>" &
"<div style='text-align:center;'>(" & Format(pSubTotalM, "#,000") & ")</div>" &
"</div>" &
"<div class='col-sm-4'>" &
"<div style='font-size:20px; text-align:center; font-weight:bold;'>Total</div>" &
"<div style='font-size:20px; text-align:center;'>" & Format(pTotalH + pTotalM, "#,000") & "</div>" &
"<div style='text-align:center;'>(" & Format(pSubTotalH + pSubTotalM, "#,000") & ")</div>" &
"</div>" &
"</div>"
pLabel.Text = pBoostrap
End Sub
Private Sub MontaGrafico(ByVal pDados As String, ByVal pCODTIPOCURSO As Integer)
Dim pScript As String
Dim pTitulo As String = ""
Dim pieChart As String = "piechart1"
If pCODTIPOCURSO = 1 Then
pTitulo = "CURSOS SUPERIORES"
pieChart = "piechart1"
Else
If pCODTIPOCURSO = 6 Then
pTitulo = "CURSOS TÉCNICOS"
pieChart = "piechart6"
End If
End If
pScript = " <script type='text/javascript'> " &
" google.charts.load('current', {'packages':['corechart']}); " &
" google.charts.setOnLoadCallback(drawChart); " &
" " &
" function drawChart() { " &
" " &
" var data = google.visualization.arrayToDataTable([ " &
" ['MATRIZ', 'QUANT'], " &
pDados &
" ]); " &
" " &
" var options = { " &
" legend: {position: 'right'}, " &
" title: '" & pTitulo & "' , " &
" backgroundColor: { fill:'transparent' }, " &
" responsive: true, " &
" width: 500, " &
" width_units: '%', " &
" is3D: true, " &
" }; " &
" " &
" var chart = new google.visualization.PieChart(document.getElementById('" & pieChart & "')); " &
" " &
" chart.draw(data, options); " &
" } " &
" " &
" </script>"
If pCODTIPOCURSO = 1 Then
LbGrafico1.Text = pScript & "<div id='" & pieChart & "' style='width:100% !important; text-align:center !important;'></div>"
Else
If pCODTIPOCURSO = 6 Then
LbGrafico2.Text = pScript & "<div id='" & pieChart & "' style='width:100% !important; text-align:center !important;'></div>"
End If
End If
End Sub
Private Sub MontaGraficoBarras(ByVal pLabel As WebControls.Label, ByVal pDados As String, ByVal pCodTipoCurso As Integer)
Dim pTitulo As String = DBNull.Value.ToString
Dim pBarChart As String = "barChart" & pCodTipoCurso
If pCodTipoCurso = 1 Then
pTitulo = "CURSOS SUPERIORES"
Else
If pCodTipoCurso = 6 Then
pTitulo = "CURSOS TÉCNICOS"
End If
End If
Dim pScript = "<script type='text/javascript'>" &
"google.charts.load('current', {packages:['corechart']}); " &
"google.charts.setOnLoadCallback(drawChart); " &
"function drawChart() { " &
" var data = google.visualization.arrayToDataTable([ " &
" ['SEXO', 'QUANT', { role: 'style' } ], " &
pDados &
" ]); " &
" " &
" var view = new google.visualization.DataView(data); " &
" view.setColumns([0, 1, " &
" { calc: 'stringify', " &
" sourceColumn: 1, " &
" type: 'string', " &
" role: 'annotation' }, " &
" 2]); " &
" " &
" var options = { " &
" title: '" & pTitulo & " - CANDIDATOS COM PONTUACAO IGUAL OU ACIMA DE 50', " &
" width: 600, " &
" height: 400, " &
" responsive: true, " &
" width_units: '%', " &
" bar: {groupWidth: '95%'}, " &
" legend: { position: 'none' }, " &
" }; " &
" var chart = new google.visualization.ColumnChart(document.getElementById('" & pBarChart & "')); " &
" chart.draw(view, options); " &
" } " &
"</script>"
pLabel.Text = pScript & "<div id='" & pBarChart & "' style='width: 100% !important; height: 400px;'></div>"
End Sub
Private Sub TotalInscritos()
Dim Ds As New Data.DataSet
Dim pLista As New WebControls.ListBox
Dim pParametro As String = DBNull.Value.ToString
Dim I As Integer
If ComboAnoLetivo.SelectedValue > 0 Then pLista.Items.Add(" C.ANOID = " & ComboAnoLetivo.SelectedValue)
If ComboFilial.SelectedValue > 0 Then pLista.Items.Add(" C.CODFILIAL = " & ComboFilial.SelectedValue)
If ComboTipoCurso.SelectedValue > 0 Then pLista.Items.Add(" C.CODTIPOCURSO = " & ComboTipoCurso.SelectedValue)
If ComboCurso.SelectedValue <> DBNull.Value.ToString Then pLista.Items.Add(" C.CODGRADE = '" & ComboCurso.SelectedValue & "' ")
If ComboTurno.SelectedValue > 0 Then pLista.Items.Add(" B.CODTURNO = " & ComboTurno.SelectedValue)
I = 0
For Each item As ListItem In pLista.Items
If I > 0 Then pParametro += " AND " & item.Value Else pParametro += item.Value
I = I + 1
Next
LbFrameGrafico1.Text = DBNull.Value.ToString
Ds = Inscritos.ConsultarTotal(pParametro)
If Not Ds Is Nothing Then
If Ds.Tables(0).Rows.Count > 0 Then
MontaGraficoBarras(LbFrameGrafico1, "['HOMENS', " & Ds.Tables(0).Rows(0)("TOTAL_HOMENS_PROVA") & ", '#0066FF']," &
"['MULHERES', " & Ds.Tables(0).Rows(0)("TOTAL_MULHERES_PROVA") & ", '#FF3399']",
ComboTipoCurso.SelectedValue)
MontaDashBoard(LbFrame1,
"Total de Inscritos",
"(abaixo de cada total o número de candidatos que fizeram a redação)",
Ds.Tables(0).Rows(0)("TOTAL_HOMENS"),
Ds.Tables(0).Rows(0)("TOTAL_HOMENS_PROVA"),
Ds.Tables(0).Rows(0)("TOTAL_MULHERES"),
Ds.Tables(0).Rows(0)("TOTAL_MULHERES_PROVA"))
Else
If Ds.Tables(0).Rows.Count = 0 Then
MontaDashBoard(LbFrame1,
"Total de Inscritos",
"(abaixo de cada total o número de candidatos que fizeram a redação)",
0, 0, 0, 0)
End If
End If
Else
If Ds Is Nothing Then
MontaDashBoard(LbFrame1,
"Total de Inscritos",
"(abaixo de cada total o número de candidatos que fizeram a redação)",
0, 0, 0, 0)
End If
End If
End Sub
Private Sub TotalAvaliados()
Dim Ds As New Data.DataSet
Dim pLista As New WebControls.ListBox
Dim pParametro As String = DBNull.Value.ToString
Dim I As Integer
If ComboAnoLetivo.SelectedValue > 0 Then pLista.Items.Add(" C.ANOID = " & ComboAnoLetivo.SelectedValue)
If ComboFilial.SelectedValue > 0 Then pLista.Items.Add(" C.CODFILIAL = " & ComboFilial.SelectedValue)
If ComboTipoCurso.SelectedValue > 0 Then pLista.Items.Add(" C.CODTIPOCURSO = " & ComboTipoCurso.SelectedValue)
If ComboCurso.SelectedValue <> DBNull.Value.ToString Then pLista.Items.Add(" C.CODGRADE = '" & ComboCurso.SelectedValue & "' ")
If ComboTurno.SelectedValue > 0 Then pLista.Items.Add(" B.CODTURNO = " & ComboTurno.SelectedValue)
pLista.Items.Add(" A.NOTA IS NOT NULL ")
I = 0
For Each item As ListItem In pLista.Items
If I > 0 Then pParametro += " AND " & item.Value Else pParametro += item.Value
I = I + 1
Next
Ds = Inscritos.ConsultarTotalAvaliados(pParametro, pParametro)
If Not Ds Is Nothing Then
If Ds.Tables(0).Rows.Count > 0 Then
MontaDashBoard(LbFrame2,
"Total de Avaliados",
"(abaixo de cada total o nº de candidatos com pontuação maior ou igual a 50)",
Ds.Tables(0).Rows(0)("TOTAL_HOMENS"),
Ds.Tables(0).Rows(0)("TOTAL_HOMENS_NOTA_ACIMA_50"),
Ds.Tables(0).Rows(0)("TOTAL_MULHERES"),
Ds.Tables(0).Rows(0)("TOTAL_MULHERES_NOTA_ACIMA_50"))
Else
If Ds.Tables(0).Rows.Count = 0 Then
MontaDashBoard(LbFrame2,
"Total de Avaliados",
"(abaixo de cada total o nº de candidatos com pontuação maior ou igual a 50)",
0, 0, 0, 0)
End If
End If
Else
If Ds Is Nothing Then
MontaDashBoard(LbFrame2,
"Total de Avaliados",
"(abaixo de cada total o nº de candidatos com pontuação maior ou igual a 50)",
0, 0, 0, 0)
End If
End If
End Sub
Private Sub PovoaFrames()
TotalInscritos()
TotalAvaliados()
End Sub
Private Sub PreparaGrafico(ByVal pCODTIPOCURSO As Integer)
Dim Ds As Data.DataSet
Dim Dr As Data.DataRow
Dim pDados As String = DBNull.Value.ToString
Ds = Inscritos.ConsultaGenerica(" SELECT CONTAR = COUNT(*), E.CODGRADE, GRADE = E.DESCRICAO, FILIAL = H.NOME, NIVEL = F.NOME " &
" FROM INSCRICAO A " &
" INNER JOIN CURSOTURNOS B On (B.ID = A.CURSOTURNOID) " &
" INNER JOIN CURSOS C ON (C.ID = B.CURSOID) " &
" INNER JOIN ANOVESTIBULAR D ON (D.ID = C.ANOID) " &
" INNER JOIN corpore.dbo.SGRADE E ON (E.CODGRADE = C.CODGRADE AND E.CODCURSO = C.CODCURSO) " &
" INNER JOIN corpore.dbo.STIPOCURSO F ON (F.CODTIPOCURSO = C.CODTIPOCURSO) " &
" INNER JOIN corpore.dbo.GFILIAL H ON (H.CODFILIAL = C.CODFILIAL AND H.CODCOLIGADA = C.CODCOLIGADA) " &
" WHERE D.ATIVO = 'True' AND C.CODTIPOCURSO = " & pCODTIPOCURSO &
" GROUP BY E.CODGRADE, E.DESCRICAO, H.NOME, F.NOME ")
If Not Ds Is Nothing Then
If Ds.Tables(0).Rows.Count > 0 Then
For I As Integer = 0 To Ds.Tables(0).Rows.Count - 1
Dr = Ds.Tables(0).Rows(I)
pDados += "['" & Dr("CODGRADE") & "', " & Dr("CONTAR") & "], "
Next
MontaGrafico(pDados, pCODTIPOCURSO)
End If
End If
End Sub
Private Sub PovoaAno()
Dim Ds As Data.DataSet
Ds = AnoLetivo.Consultar("")
ComboAnoLetivo.DataSource = Ds
ComboAnoLetivo.DataBind()
ComboAnoLetivo.Items.Insert(0, New ListItem("--SELECIONE--", "0"))
End Sub
Private Sub PovoaFilial()
Dim Ds As Data.DataSet
'Ds = Coligada.ConsultaFilial(" CODCOLIGADA = 1 " &
' " AND CODFILIAL IN (2, 3, 4, 5, 6) ")
Ds = Coligada.ConsultaFilial(" CODCOLIGADA = 1 " &
" AND CODFILIAL IN (SELECT X.CODFILIAL " &
" FROM CURSOS X " &
" WHERE X.ANOID = " & ComboAnoLetivo.SelectedValue &
" GROUP BY X.CODFILIAL) ")
ComboFilial.DataSource = Ds
ComboFilial.DataBind()
ComboFilial.Items.Insert(0, New ListItem("--SELECIONE--", "0"))
End Sub
Private Sub PovoaTipoCurso()
Dim Ds As Data.DataSet
Ds = Coligada.ConsultaTipoCurso(" A.CODCOLIGADA = 1 " &
" And A.CODFILIAL = " & ComboFilial.SelectedValue &
" And A.CODTIPOCURSO IN (SELECT X.CODTIPOCURSO " &
" FROM CURSOS X " &
" WHERE X.ANOID = " & ComboAnoLetivo.SelectedValue &
" GROUP BY X.CODTIPOCURSO) ")
ComboTipoCurso.DataSource = Ds
ComboTipoCurso.DataBind()
ComboTipoCurso.Items.Insert(0, New ListItem("--SELECIONE--", "0"))
End Sub
Private Sub PovoaCurso()
Dim Ds As Data.DataSet
Ds = Coligada.ConsultaCurso(" B.CODCOLIGADA = 1 " &
" And B.CODFILIAL = " & ComboFilial.SelectedValue &
" And B.CODTIPOCURSO = " & ComboTipoCurso.SelectedValue &
" And A.CODGRADE IN (SELECT X.CODGRADE FROM CURSOS X " &
" WHERE X.ANOID = " & ComboAnoLetivo.SelectedValue &
" And X.CODFILIAL = " & ComboFilial.SelectedValue &
" And X.CODTIPOCURSO = " & ComboTipoCurso.SelectedValue & " ) ")
ComboCurso.DataSource = Ds
ComboCurso.DataBind()
ComboCurso.Items.Insert(0, New ListItem("--SELECIONE--", "XX"))
End Sub
Private Sub PovoaTurno()
Dim Ds As Data.DataSet
Ds = Coligada.ConsultaTurno(" A.CODFILIAL = " & ComboFilial.SelectedValue &
" And A.CODTIPOCURSO = " & ComboTipoCurso.SelectedValue &
" And A.CODTURNO IN (SELECT X.CODTURNO " &
" FROM CURSOTURNOS X " &
" INNER JOIN CURSOS Z ON (Z.ID = X.CURSOID) " &
" WHERE Z.ANOID = " & ComboAnoLetivo.SelectedValue &
" And Z.CODGRADE = '" & ComboCurso.SelectedValue & "' " &
" AND Z.CODFILIAL = " & ComboFilial.SelectedValue &
" AND Z.CODTIPOCURSO = " & ComboTipoCurso.SelectedValue & ") ")
ComboTurno.DataSource = Ds
ComboTurno.DataBind()
ComboTurno.Items.Insert(0, New ListItem("--SELECIONE--", "0"))
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Inscritos.CancelaTodasRedacoesTecnicos()
PovoaAno()
PovoaFilial()
PovoaTipoCurso()
PovoaCurso()
PovoaTurno()
PovoaFrames()
PreparaGrafico(1)
PreparaGrafico(6)
End If
End Sub
Protected Sub ComboFilial_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboFilial.SelectedIndexChanged
PovoaTipoCurso()
PovoaCurso()
PovoaTurno()
PovoaFrames()
End Sub
Protected Sub ComboTipoCurso_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboTipoCurso.SelectedIndexChanged
PovoaCurso()
PovoaTurno()
PovoaFrames()
End Sub
Protected Sub ComboCurso_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboCurso.SelectedIndexChanged
PovoaTurno()
PovoaFrames()
End Sub
Protected Sub ComboTurno_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboTurno.SelectedIndexChanged
PovoaFrames()
End Sub
Protected Sub ComboAnoLetivo_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboAnoLetivo.SelectedIndexChanged
'Inscritos.CancelaTodasRedacoesTecnicos()
PovoaFilial()
PovoaTipoCurso()
PovoaCurso()
PovoaTurno()
PovoaFrames()
End Sub
End Class