Show data on screen

Asked

Viewed 102 times

0

I’m generating charts and the data comes through a database query.

These dice are played in a two-position array.

In the "Labels" Script that should return the name of the vendors, in the case they are in the second position of the array [1]

And in "date" you must return the values, which in this case are in the first position of the array [0].

But if I keep both information the screen goes blank, if I just put one of them or names or values works.

Would anyone know how to make it work?

<html>

<head>
	<title>Bar Chart</title>
        <script src="chart_master/dist/Chart.bundle.js"></script>
        <script src="chart_master/Chart.js-master/samples/utils.js"></script>
	<style>
	canvas {
		-moz-user-select: none;
		-webkit-user-select: none;
		-ms-user-select: none;
	}
	</style>
</head>

<body>
     <?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
     ?>
	<div  style="width: 100%;">
		<canvas id="desafios"></canvas>
	</div>
       
	<script>
                var color = Chart.helpers.color;
                var horizontalBarChartData = {
                labels:  [
                    <?php
                         while ($dash1 = ibase_fetch_row($resultado)){
                            echo "'" .trim($dash1['1'])."',";
                         }
                  ?>
                ],
                datasets: [{
                    label: 'Desafios',
                    backgroundColor: color(window.chartColors.red).alpha(0.5).rgbString(),
                    borderColor: window.chartColors.red,
                    borderWidth: 3,
                    data: [
                    <?php
                         while ($dash1 = ibase_fetch_row($resultado)){
                            echo trim($dash1['0']).',';
                         }
                    ?>
                    ] 
                    }]

                };
		window.onload = function() {
			var ctx = document.getElementById('desafios').getContext('2d');
			window.myHorizontalBar = new Chart(ctx, {
				type: 'horizontalBar',
				data: horizontalBarChartData,
				options: {
					// Elements options apply to all of the options unless overridden in a dataset
					// In this case, we are setting the border of each horizontal bar to be 2px wide
					elements: {
						rectangle: {
							borderWidth: 2
						}
					},
					responsive: true,
					legend: {
						
					},
					title: {
						display: true,
						text: 'Desafios'
					}
				}
			});

		};
	</script>
</body>

</html>

  • Executes the var_dump($dash1); within your while, see what comes up.

  • I was able to make the data appear on the screen, but, my query returns 4 records but only 3 appear on the screen, I put the code this way. while ($dash1 = ibase_fetch_row($result)){ echo Trim($dash1['0']). ','; } I can’t understand why only 3 of the 4 records appear

  • @Alexandreprezzi put this information in your question. All the details you can put there are important to finding a solution.

  • @Joãomartins changed the question, see if it was clearer and if you need more information let me know. Thanks

No answers

Browser other questions tagged

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