{"absolute_url": "https://alexjosesilva.snipt.net/graficos-google-charts-vindo-do-banco/", "blog_post": true, "code": " 'Weekly Task', 'type' => 'string'),\n array('label' => 'Percentage', 'type' => 'number')\n\n);\n\n$rows = array();\nwhile($r = mysql_fetch_assoc($sth)) {\n $temp = array();\n // the following line will be used to slice the Pie chart\n $temp[] = array('v' => (string) $r['nomePessoa']); \n\n // Values of each slice\n $temp[] = array('v' => (int) $r['idpessoa']); \n $rows[] = array('c' => $temp);\n}\n\n$table['rows'] = $rows;\n$jsonTable = json_encode($table);\n//echo $jsonTable;\n?>\n\n\n \n \n \n \n \n \n\n \n \n
\n \n", "created": "2016-06-15T23:27:04.669999", "description": "criar graficos do google charts atraves do mysql", "description_rendered": "criar graficos do google charts atraves do mysql", "embed_url": "https://snipt.net/embed/4541dd88174e0618c2ab1b302f830852/", "full_absolute_url": "https://alexjosesilva.snipt.net/graficos-google-charts-vindo-do-banco/", "id": 147207, "lexer": "php", "line_count": 83, "log_entries": [{"code": " 'Weekly Task', 'type' => 'string'),\n array('label' => 'Percentage', 'type' => 'number')\n\n);\n\n$rows = array();\nwhile($r = mysql_fetch_assoc($sth)) {\n $temp = array();\n // the following line will be used to slice the Pie chart\n $temp[] = array('v' => (string) $r['nomePessoa']); \n\n // Values of each slice\n $temp[] = array('v' => (int) $r['idpessoa']); \n $rows[] = array('c' => $temp);\n}\n\n$table['rows'] = $rows;\n$jsonTable = json_encode($table);\n//echo $jsonTable;\n?>\n\n\n \n \n \n \n \n \n\n \n \n
\n \n", "created": "2016-06-15T23:27:04.688661", "diff": "--- \n+++ \n@@ -0,0 +1,83 @@\n+ 'Weekly Task', 'type' => 'string'),\n+ array('label' => 'Percentage', 'type' => 'number')\n+\n+);\n+\n+$rows = array();\n+while($r = mysql_fetch_assoc($sth)) {\n+ $temp = array();\n+ // the following line will be used to slice the Pie chart\n+ $temp[] = array('v' => (string) $r['nomePessoa']); \n+\n+ // Values of each slice\n+ $temp[] = array('v' => (int) $r['idpessoa']); \n+ $rows[] = array('c' => $temp);\n+}\n+\n+$table['rows'] = $rows;\n+$jsonTable = json_encode($table);\n+//echo $jsonTable;\n+?>\n+\n+\n+ \n+ \n+ \n+ \n+ \n+ \n+\n+ \n+ \n+
\n+ \n+", "user": "alexjosesilva"}], "meta": null, "modified": "2016-12-29T11:40:37.559404", "publish_date": "2016-06-15T23:27:04.633026", "raw_url": "/raw/4541dd88174e0618c2ab1b302f830852/", "resource_uri": "/api/public/snipt/147207/", "slug": "graficos-google-charts-vindo-do-banco", "stylized": "
 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83
<?php\n$con=mysql_connect("localhost","root","") or die("Failed to connect with database!!!!");\n\nmysql_select_db("bancoteste", $con); \n// The Chart table contains two fields: weekly_task and percentage\n// This example will display a pie chart. If you need other charts such as a Bar chart, you will need to modify the code a little to make it work with bar chart and other charts\n$sth = mysql_query("SELECT * FROM pessoa");\n\n/*\n---------------------------\nexample data: Table (Chart)\n--------------------------\nweekly_task     percentage\nSleep           30\nWatching Movie  40\nwork            44\n*/\n\n$rows = array();\n//flag is not needed\n$flag = true;\n$table = array();\n$table['cols'] = array(\n\n    // Labels for your chart, these represent the column titles\n    // Note that one column is in "string" format and another one is in "number" format as pie chart only required "numbers" for calculating percentage and string will be used for column title\n    array('label' => 'Weekly Task', 'type' => 'string'),\n    array('label' => 'Percentage', 'type' => 'number')\n\n);\n\n$rows = array();\nwhile($r = mysql_fetch_assoc($sth)) {\n    $temp = array();\n    // the following line will be used to slice the Pie chart\n    $temp[] = array('v' => (string) $r['nomePessoa']); \n\n    // Values of each slice\n    $temp[] = array('v' => (int) $r['idpessoa']); \n    $rows[] = array('c' => $temp);\n}\n\n$table['rows'] = $rows;\n$jsonTable = json_encode($table);\n//echo $jsonTable;\n?>\n\n<html>\n  <head>\n    <!--Load the Ajax API-->\n    <script type="text/javascript" src="https://www.google.com/jsapi"></script>\n    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>\n    <script type="text/javascript">\n\n    // Load the Visualization API and the piechart package.\n    google.load('visualization', '1', {'packages':['corechart']});\n\n    // Set a callback to run when the Google Visualization API is loaded.\n    google.setOnLoadCallback(drawChart);\n\n    function drawChart() {\n\n      // Create our data table out of JSON data loaded from server.\n      var data = new google.visualization.DataTable(<?=$jsonTable?>);\n      var options = {\n           title: 'My Weekly Plan',\n          is3D: 'true',\n          width: 800,\n          height: 600\n        };\n      // Instantiate and draw our chart, passing in some options.\n      // Do not forget to check your div ID\n      var chart = new google.visualization.PieChart(document.getElementById('chart_div'));\n      chart.draw(data, options);\n    }\n    </script>\n  </head>\n\n  <body>\n    <!--this is the div that will hold the pie chart-->\n    <div id="chart_div"></div>\n  </body>\n</html>\n
\n
", "tags": [{"absolute_url": "/public/tag/mysql/", "id": 1, "name": "mysql", "resource_uri": "/api/public/tag/1/", "snipts": "/api/public/snipt/?tag=1"}, {"absolute_url": "/public/tag/php/", "id": 9, "name": "php", "resource_uri": "/api/public/tag/9/", "snipts": "/api/public/snipt/?tag=9"}, {"absolute_url": "/public/tag/sql/", "id": 27, "name": "sql", "resource_uri": "/api/public/tag/27/", "snipts": "/api/public/snipt/?tag=27"}, {"absolute_url": "/public/tag/html/", "id": 67, "name": "html", "resource_uri": "/api/public/tag/67/", "snipts": "/api/public/snipt/?tag=67"}, {"absolute_url": "/public/tag/json/", "id": 265, "name": "json", "resource_uri": "/api/public/tag/265/", "snipts": "/api/public/snipt/?tag=265"}, {"absolute_url": "/public/tag/google-charts/", "id": 2071, "name": "google charts", "resource_uri": "/api/public/tag/2071/", "snipts": "/api/public/snipt/?tag=2071"}], "title": "Graficos Google Charts vindo do Banco", "user": {"absolute_url": "/alexjosesilva/", "email_md5": "aeee1adb46d99d6d54bb7b0d325a259f", "id": 18522, "resource_uri": "/api/public/user/18522/", "snipts": "/api/public/snipt/?user=18522", "snipts_count": 6, "username": "alexjosesilva"}}