jpgraph Empty square php line Chart

Asked

Viewed 19 times

1

Here my code receive data of a form:

if(empty($_POST["GESTOR"]))
{
    $where_GESTOR = "";
} 
else 
{
    $GESTOR = implode( "','" , $_POST["GESTOR"]);
    $where_GESTOR = " and B.GESTOR in ('$GESTOR') ";
}
if(empty($_POST["FORNECEDOR"]))
{
    $where_FORNECEDOR = '';
} 
else 
{
    $FORNECEDOR = implode("','" , $_POST["FORNECEDOR"]);
    $where_FORNECEDOR = "and B.FORNECEDOR in ('$FORNECEDOR') ";
}

Here I put the pack of jpgraph and a do the DB Connection.

require_once ('../jpgraph/src/jpgraph.php');
require_once ('../jpgraph/src/jpgraph_line.php');
include ('../db/bdconnect.php');

Here I put the first data of my Chart.

$query_aceitar_nota = "SELECT t.QUANTIDADE as QUANTIDADE
FROM
(SELECT DISTINCT
                IIF(A.APROVACAO='S', 'ACEITAR NOTA', 'NÃO ACEITAR NOTA') AS APROVACAO,
                COUNT(A.APROVACAO) AS QUANTIDADE,
                A.DT_CADASTRO
FROM [PORTALFINANCEIRO].[DBO].[TB_SGNF_APROVACAO] AS A
LEFT JOIN [PORTALFINANCEIRO].[dbo].[TB_SGNF_GED_SGNF_HISTORICO] AS B ON A.PROTOCOLO = B.PROTOCOLO
WHERE A.DT_CADASTRO BETWEEN DATEADD(DAY, -931, GETDATE()) AND GETDATE()"
.$where_GESTOR.$where_FORNECEDOR.
"GROUP BY A.APROVACAO, A.DT_CADASTRO) AS t
WHERE t.APROVACAO = 'ACEITAR NOTA'
ORDER BY t.DT_CADASTRO";
$result = mssql_query($query_aceitar_nota, $con);
$datay1 = [];
$x =0;
while($row = mssql_fetch_array($result, MSSQL_BOTH)){
  $datay1[$x] = $row['QUANTIDADE'];
  $x++;
}

Here I put the Second data of my Chart.

$query_nao_aceitar_nota = "SELECT t.QUANTIDADE as QUANTIDADE
FROM
(SELECT DISTINCT
                IIF(A.APROVACAO='S', 'ACEITAR NOTA', 'NÃO ACEITAR NOTA') AS APROVACAO,
                COUNT(A.APROVACAO) AS QUANTIDADE,
                A.DT_CADASTRO
FROM [PORTALFINANCEIRO].[DBO].[TB_SGNF_APROVACAO] AS A
LEFT JOIN [PORTALFINANCEIRO].[dbo].[TB_SGNF_GED_SGNF_HISTORICO] AS B ON A.PROTOCOLO = B.PROTOCOLO
WHERE A.DT_CADASTRO BETWEEN DATEADD(DAY, -931, GETDATE()) AND GETDATE()"
.$where_GESTOR.$where_FORNECEDOR.
"GROUP BY A.APROVACAO, A.DT_CADASTRO) AS t
WHERE t.APROVACAO = 'NÃO ACEITAR NOTA'
ORDER BY t.DT_CADASTRO";
$result_nao = mssql_query($query_nao_aceitar_nota, $con);
$datay2 = [];
$x2 =0;
while($row2 = mssql_fetch_array($result_nao, MSSQL_BOTH)){
  $datay2[$x2] = $row2['QUANTIDADE'];
  $x2++;
}

Here o Plot all information in my line Chart.

$graph = new Graph(850,450);
$graph->SetScale("textlin");
$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(false);
$graph->title->Set('Taxa de aceitação da NF');
$graph->SetBox(false);
$graph->SetMargin(50,30,16,103);
$graph->img->SetAntiAliasing();
$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$query_dt_cadastro = "SELECT DISTINCT FORMAT(t.DT_CADASTRO, 'MM-dd') AS DT_CADASTRO
FROM
(SELECT DISTINCT
    IIF(APROVACAO='S', 'ACEITAR NOTA', 'NÃO ACEITAR NOTA') AS APROVACAO,
    COUNT(APROVACAO) AS QUANTIDADE,
    DT_CADASTRO
FROM [PORTALFINANCEIRO].[DBO].[TB_SGNF_APROVACAO]
WHERE DT_CADASTRO BETWEEN DATEADD(DAY, -931, GETDATE()) AND GETDATE()
GROUP BY APROVACAO, DT_CADASTRO) AS t
ORDER BY 1";
$result_dt_cadastro = mssql_query($query_dt_cadastro, $con);
$dt_cadastro = [];
$x3 =0;
while($row3 = mssql_fetch_array($result_dt_cadastro, MSSQL_BOTH)){
  $dt_cadastro[$x3] = $row3['DT_CADASTRO'];
  $x3++;
}
$graph->xaxis->SetTickLabels($dt_cadastro);
$graph->xgrid->SetColor('#E3E3E3');
$p1 = new LinePlot($datay1);
$graph->Add($p1);
$p1->SetColor("#6495ED");
$p1->SetLegend('ACEITAR NOTA');
$p2 = new LinePlot($datay2);
$graph->Add($p2);
$p2->SetColor("#B22222");
$p2->SetLegend('NÃO ACEITAR NOTA');
$graph->legend->SetFrameWeight(1);
$graph->Stroke();
  • Use Chartjs, don’t use that, it’s easier and faster and simple to work with.

No answers

Browser other questions tagged

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