joaocasta Posted September 22, 2012 at 11:18 AM Report #476181 Posted September 22, 2012 at 11:18 AM Boas tardes, consegui fazer o codigo em PHP para apanhar os dados, mas agora queria colocar aqueles dados que tenho num gráfico circular.. <?php $sql = "SELECT distrito, round(count(`distrito`) / (SELECT count(`id`) FROM `users`), 2) * 100 AS 'percentagemregiao' FROM `users` GROUP BY `distrito`"; $reshabitacao = mysql_query($sql) or die(mysql_error()); while ($row1 = mysql_fetch_array($reshabitacao)) { echo $row1['distrito'].": "; echo $row1['percentagemregiao']."%</br>"; } ?> Tenho isto mas queria usar os dados que tenho para fazer um gráfico.
pmg Posted September 22, 2012 at 11:20 AM Report #476182 Posted September 22, 2012 at 11:20 AM Há uns tempos usei o JpGraph para esse efeito. What have you tried? Não respondo a dúvidas por PM A minha bola de cristal está para compor; deve ficar pronta para a semana. Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código!
HappyHippyHippo Posted September 22, 2012 at 11:24 AM Report #476183 Posted September 22, 2012 at 11:24 AM a google tem uma api para isso https://developers.google.com/chart/ IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
joaocasta Posted September 22, 2012 at 03:14 PM Author Report #476204 Posted September 22, 2012 at 03:14 PM Há mais formas?
yoda Posted September 22, 2012 at 07:45 PM Report #476229 Posted September 22, 2012 at 07:45 PM Há, procura no google por "dynamic javascript / image charts" before you post, what have you tried? - http://filipematias.info sense, purpose, direction
Cerzedelo Posted September 24, 2012 at 07:53 AM Report #476318 Posted September 24, 2012 at 07:53 AM (edited) Pode utilizar o phpchart. Ver em http://phpchart.net/. Edited September 24, 2012 at 07:54 AM by Cerzedelo
joaocasta Posted September 29, 2012 at 09:30 AM Author Report #477014 Posted September 29, 2012 at 09:30 AM <script type="text/javascript"> function drawVisualization() { // Create and populate the data table. var data = google.visualization.arrayToDataTable([ <?php $sql = "SELECT distrito, count(`distrito`) AS 'percentagemregiao' FROM `users` GROUP BY `distrito`"; $reshabitacao = mysql_query($sql) or die(mysql_error()); while ($row1 = mysql_fetch_array($reshabitacao)) { ['Task', 'Hours per Day'], ['Work', 11], ['Eat', 2], ['Commute', 2], ['Watch TV', 3], ['Sleep', 7] } ?> ]); // Create and draw the visualization. new google.visualization.PieChart(document.getElementById('visualization')). draw(data, {title:"So, how was your day?"}); } google.setonloadCallback(drawVisualization); </script> <?php $sql = "SELECT distrito, count(`distrito`) AS 'percentagemregiao' FROM `users` GROUP BY `distrito`"; $reshabitacao = mysql_query($sql) or die(mysql_error()); while ($row1 = mysql_fetch_array($reshabitacao)) { ['Task', 'Hours per Day'], ['Work', 11], ['Eat', 2], ['Commute', 2], ['Watch TV', 3], ['Sleep', 7] } ?> na parte dos parenteses rectos, onde estão os números queria adicionar o "$row1['distrito']" para poder aparecer o numero de vezes q aquele distrito tem. mas acho q tenho ali coisas a mais. Podem ajudar-me?
HappyHippyHippo Posted September 29, 2012 at 09:36 AM Report #477015 Posted September 29, 2012 at 09:36 AM a mim parece que tens é algo a menos: /* linha de PHP */<?php /* linha de PHP */$sql = "SELECT distrito, /* linha de PHP */ count(`distrito`) AS 'percentagemregiao' /* linha de PHP */ FROM `users` /* linha de PHP */GROUP BY `distrito`"; /* linha de PHP */$reshabitacao = mysql_query($sql) or die(mysql_error()); /* linha de PHP */while ($row1 = mysql_fetch_array($reshabitacao)) { /* linha de PHP */ ['Task', 'Hours per Day'], /* Isto não deveria ser Javascript ??? */ /* linha de PHP */ ['Work', 11], /* Isto não deveria ser Javascript ??? */ /* linha de PHP */ ['Eat', 2], /* Isto não deveria ser Javascript ??? */ /* linha de PHP */ ['Commute', 2], /* Isto não deveria ser Javascript ??? */ /* linha de PHP */ ['Watch TV', 3], /* Isto não deveria ser Javascript ??? */ /* linha de PHP */ ['Sleep', 7] /* Isto não deveria ser Javascript ??? */ /* linha de PHP */ } /* linha de PHP */?> isso para não falar que o código não fará muito sentido. um ciclo de php com informação da base de dados que não faz nada com a informação ... IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
joaocasta Posted September 29, 2012 at 10:30 AM Author Report #477017 Posted September 29, 2012 at 10:30 AM que posso fazer entao?
yoda Posted September 29, 2012 at 11:11 AM Report #477020 Posted September 29, 2012 at 11:11 AM Informa qual é o tipo de dados que vêm da base de dados. Existem várias formas de fazer o que pretendes. before you post, what have you tried? - http://filipematias.info sense, purpose, direction
joaocasta Posted September 29, 2012 at 11:29 AM Author Report #477023 Posted September 29, 2012 at 11:29 AM como assim informar yoda?
yoda Posted September 29, 2012 at 12:09 PM Report #477029 Posted September 29, 2012 at 12:09 PM Mostra o exemplo de um resultado (row) da base de dados. before you post, what have you tried? - http://filipematias.info sense, purpose, direction
joaocasta Posted September 29, 2012 at 12:27 PM Author Report #477032 Posted September 29, 2012 at 12:27 PM (edited) ja consegui por aquilo a funcionar mas penso q o while nao está correcto. <?php require_once "config.php"; function rand_colorCode(){ $r = dechex(mt_rand(0,255)); // generate the red component $g = dechex(mt_rand(0,255)); // generate the green component $b = dechex(mt_rand(0,255)); // generate the blue component $rgb = $r.$g.$b; if($r == $g && $g == $b){ $rgb = substr($rgb,0,3); // shorter version } return '#'.$rgb; } $code = rand_colorCode(); echo 'This code is <span style="color:'.$code.'">lol</span>'; ?> <!-- You are free to copy and use this sample in accordance with the terms of the Apache license (http://www.apache.org/licenses/LICENSE-2.0.html) --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title> Google Visualization API Sample </title> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load('visualization', '1', {packages: ['corechart']}); </script> <?php $sql = "SELECT distrito, count(`distrito`) AS 'percentagemregiao' FROM `users` GROUP BY `distrito`"; $reshabitacao = mysql_query($sql) or die(mysql_error()); while ($row1 = mysql_fetch_array($reshabitacao)) { ?> <script type="text/javascript"> function drawVisualization() { // Create and populate the data table. var data = google.visualization.arrayToDataTable([ ['<?php echo $row1['distrito']?>', <?php echo $row1['percentagemregiao']; ?>], ['<?php echo $row1['distrito']?>', <?php echo $row1['percentagemregiao']; ?>] ]); // Create and draw the visualization. new google.visualization.PieChart(document.getElementById('visualization')). draw(data, {title:"So, how was your day?"}); } google.setonloadCallback(drawVisualization); </script> <?php } ?> </head> <body style="font-family: Arial;border: 0 none;"> <div id="visualization" style="width: 600px; height: 400px;"></div> </body> </html> Edited September 29, 2012 at 12:36 PM by joaocasta
HappyHippyHippo Posted September 29, 2012 at 02:16 PM Report #477040 Posted September 29, 2012 at 02:16 PM já viste o html/javascript resultante ? é que de outra forma não aprendes ... IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
joaocasta Posted September 29, 2012 at 02:45 PM Author Report #477044 Posted September 29, 2012 at 02:45 PM (edited) no opera deu-me isto: This code is <span style="color:#2e39a1">lol</span> <!-- You are free to copy and use this sample in accordance with the terms of the Apache license (http://www.apache.org/licenses/LICENSE-2.0.html) --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd%22> <html xmlns="http://www.w3.org/1999/xhtml%22> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title> Google Visualization API Sample </title> <script type="text/javascript" src="http://www.google.com/jsapi%22></script> <script type="text/javascript"> google.load('visualization', '1', {packages: ['corechart']}); </script> <script type="text/javascript"> function drawVisualization() { // Create and populate the data table. var data = google.visualization.arrayToDataTable([ ['LOL', 1], ['LOL', 1] ]); // Create and draw the visualization. new google.visualization.PieChart(document.getElementById('visualization')). draw(data, {title:"So, how was your day?"}); } google.setonloadCallback(drawVisualization); </script> <script type="text/javascript"> function drawVisualization() { // Create and populate the data table. var data = google.visualization.arrayToDataTable([ ['Set?bal', 4], ['Set?bal', 4] ]); // Create and draw the visualization. new google.visualization.PieChart(document.getElementById('visualization')). draw(data, {title:"So, how was your day?"}); } google.setonloadCallback(drawVisualization); </script> </head> <body style="font-family: Arial;border: 0 none;"> <div id="visualization" style="width: 600px; height: 400px;"></div> </body> </html> e no chrome onde está LOL, diz Setubal, e á frente 4. Edited September 29, 2012 at 02:55 PM by joaocasta
HappyHippyHippo Posted September 29, 2012 at 03:34 PM Report #477047 Posted September 29, 2012 at 03:34 PM tens um ciclo no código e tens repetição no resultado, achas que consegues ver o que necessitas de alterar para o resutlado se aproximar do exemplo dado no site ? (olha que não faço ideia que biblioteca estás a usar) IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
joaocasta Posted September 29, 2012 at 09:03 PM Author Report #477083 Posted September 29, 2012 at 09:03 PM Problema resolvido.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now