pie chart 3 data colomn its not working plis help

17 views
Skip to first unread message

yoga alfian

unread,
May 4, 2020, 6:22:49 AM5/4/20
to Google Visualization API

i want to show 3 data colomn in pie chart, but just showing 2 colomn. if i used bar, its working. i want to showing storage_type,storage_used and storage_free but just storage_type and storage_used.but if i test with bar chart its working, but cannot working with pie chart.



this is my db


this is my output


<?Php
require "configdashboard.php";// Database connection

if($stmt = $connection->query("SELECT ,storage_used,storage_free FROM storage WHERE storage_type ='fujitsu'")){
   
while ($row = $stmt->fetch_row()) {
   $php_data_array
[] = $row; // Adding to array
   
}}
   
   echo
"<script>
        var my_2d = "
.json_encode($php_data_array)."
   </script>"
;
?>

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
                       
<script type="text/javascript">

// Load the Visualization API and the corechart package.
                                google
.charts.load('current', {packages: ['corechart']});
                                google
.charts.setOnLoadCallback(drawChart);
         
                               
function drawChart() {

                                       
// Create the data table.
                                       
var data = new google.visualization.DataTable();
                                        data
.addColumn('string', 'type');
                                        data
.addColumn('number', 'used');
                                        data
.addColumn('number', 'free');
               
                                       
for(i = 0; i < my_2d.length; i++)
                                        data
.addRow([my_2d[i][0], parseInt(my_2d[i][1]),parseInt(my_2d[i][2])]);
                                       
var options = {                        
                                       
};

               
                                       
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
                                        chart
.draw(data, options);
                               
}

</script>
Masukkan kode di sini...

Masukkan kode di sini...

Reply all
Reply to author
Forward
0 new messages