Graphics with PHP

Asked

Viewed 185 times

-1

I’m having trouble generating charts using data from the bank.

I have a query in the database that generates an array as a result. (Follow below)

<?php
            require_once './setaqueryDash.php';
            require_once './conecta.php';
            $resultado = ibase_query($CONEXAO_TERM, QueryDashDesafios(substr($loja_selecionada, 0,3),$data_dash));//executa query e armazena o resultado em um array


             while ($dash1 = ibase_fetch_row($resultado)){
                $dataPoints[] = ['y' => $dash1['0'],
                                 'label'  => $dash1['1']
                                ]; 
            }
?>

I have tested and the data of this array is correct, it is the data that I really want...

My question is how to make this data be those of the Graph. Follow graph generation code:

<script>
		var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
		var color = Chart.helpers.color;
		var horizontalBarChartData = {
			labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], //exemplo
//                        labels: "aqui gostaria dos meus dados"
			datasets: [{
				label: 'Dataset 1',
				backgroundColor: color(window.chartColors.blue).alpha(0.5).rgbString(),
				borderColor: window.chartColors.blue,
				borderWidth: 1,
//                              data: "aqui gostaria dos meus dados",
				data: [
					125000,
					125000,
					125000,
					125000,
					125000,
					125000,
					125000
				] // como ta no exemplo
			}]

		};

In that case I would like to bring the Labels and Data from the array.

Thank you...

  • I’m actually wondering if I can wear something like that....

1 answer

0

If you can use the google API, it’s very simple

Just select the data you want :

$sql = "SELECT sum(dados1) FROM Table WHERE x='y' "
$result = $conn->query($sql);
  if ($result->num_rows > 0) {
     while($row = $result->fetch_assoc()) {
       //codigo js do google charts onde associa o valor a row(não está todo)
       echo "<script> function drawChart1() {
       var data = google.visualization.arrayToDataTable([
      ['Mês', ' Vendas'],
      ['Janeiro ',  ".$row['y']."]);";
    echo "var options = {
                    title: 'Titulo ',
                    curveType: 'function',
                    legend: { position: 'bottom' }"
    echo" var chart = new google.visualization.LineChart(document.getElementById('curve_chart2'));

    chart.draw(data, options);"
    }
  else{ echo "falhou"
      }

Google Charts

I leave here the current link:

https://developers.google.com/chart/ -11/01/2018 12:30 En

  • I’m using https://www.chartjs.org/docs/latest/ (chartjs), it’s kind of hard to adjust the graphics, especially when you have to put more than one graph on the screen, but little by little. Thanks for the tip.

Browser other questions tagged

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