Results above 10 data to display in charts by google Charts

Asked

Viewed 63 times

0

Hello, I would like to know if you can insert some chart by google Charts with data over 10 data, because I’m trying here and I can not, only displays 10 data above this generates an error. Someone has already entered more than 10 data ??

  • You could put the code you’ve tried to do?

1 answer

0

PHP


/* Your Database Name */
$dbname = 'eleicao';

/* Your Database User Name and Passowrd */
$username = 'root';
$password = '';

try {
  /* Establish the database connection */
  $conn = new PDO("mysql:host=localhost;dbname=$dbname", $username, $password);
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  /* select all the weekly tasks from the table googlechart */
  $result = $conn->query('SELECT * FROM candidatura');


  $rows = array();
  $table = array();
  $table['cols'] = array(

    // Labels for your chart, these represent the column titles.
    /*
        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 Slice title
    */

    array('label' => 'candidato', 'type' => 'string'),
    array('label' => 'votos', 'type' => 'number')

);
    /* Extract the information from $result */
    foreach($result as $r) {

      $temp = array();

      // the following line will be used to slice the Pie chart

      $temp[] = array('v' => (string) $r['candidato']);

      // Values of each slice

      $temp[] = array('v' => (int) $r['votos']);
      $rows[] = array('c' => $temp);
    }

$table['rows'] = $rows;

// convert data into JSON format
$jsonTable = json_encode($table);
//echo $jsonTable;
} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
}

?>

HTML

// Load the Visualization API and the piechart package. google.load('visualization', '1', {'packages':['corechart']}); // Set a callback to run when the Google Visualization API is loaded. google.setOnLoadCallback(drawChart); function drawChart() { // Create our data table out of JSON data loaded from server. var data = new google.visualization.DataTable(<?=$jsonTable?>); var options = { title: 'Resultado das Eleições 2014 - Minas Gerais - Deputado Estadual', is3D: 'true', width: 800, height: 600 }; // Instantiate and draw our chart, passing in some options. // Do not forget to check your div ID var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); chart.draw(data, options); } </script> </head> <body> <!--this is the div that will hold the pie chart--> <div id="chart_div"></div> </body> </html>

Browser other questions tagged

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