//am I right?
<html>
    <head>
        <script language="javascript" type="text/javascript" 
src="js/jquery1.6.1.min.js"></script>
        <script language="javascript" type="text/javascript" 
src="js/jquery.barchart.min.js"></script>
        <script language="javascript" type="text/javascript" 
src="js/barRenderer.min.js"></script>
        <script language="javascript" type="text/javascript" 
src="js/categoryAxisRenderer.min.js"></script>
        <script language="javascript" type="text/javascript" 
src="js/pointLabels.min.js"></script>
        <script type="text/javascript">
<?php
    $dataArray = array(); 
    
    $con=mysqli_connect("localhost","root","","posnic");
    
    // set the data column labels (data series names) here
// $dataArray[] = array('Category', 'Count');
    $dataArray[] = array('Total Number of Products', '$NumProducts = 
$row[0]');
$dataArray[] = array('Total Number of Sales','$Numtemp = $row[0]');
$dataArray[] = array('Total number of Suppliers', '$NumSup = $row[0]');
$dataArray[] = array('Total Number of Customers:', '$NumCus = $row[0]');
    
    //1
    $result = mysqli_query($con,"SELECT COUNT(*) FROM stock_avail");
    $row = mysqli_fetch_array($result);
    
    //2
    $result = mysqli_query($con,"SELECT COUNT(*) FROM stock_sales"); //edit 
sql here
    $row = mysqli_fetch_array($result);
    
    //2
    $result = mysqli_query($con,"SELECT COUNT(*) FROM supplier_details"); 
//edit sql here
    $row = mysqli_fetch_array($result);
    
    //2
    $result = mysqli_query($con,"SELECT COUNT(*) FROM customer_details"); 
//edit sql here
    $row = mysqli_fetch_array($result);
    
    $json = json_encode($dataArray, JSON_NUMERIC_CHECK);
?>

            google.load("visualization", "1", {packages:["corechart"]});
            google.setOnLoadCallback(drawChart);
            function drawChart() {
                var data = google.visualization.arrayToDataTable(<?php echo 
$json; ?>);

                var options = {
                    title: 'Company Performance',
                    hAxis: {
                        title: 'Year',
                        titleTextStyle: {
                            color: 'red'
                        }
                    }
                };

                var chart = new 
google.visualization.ColumnChart(document.getElementById('chart_div'));
                chart.draw(data, options);
            }
        </script>
    </head>
    <body>
        <div id="chart_div" style="height:200px;width:800px;"></div>
    </body>
</html>

On Tuesday, 17 June 2014 02:20:56 UTC+8, Andrew Gallant wrote:
>
> Here's one way you could do it:
>
> <html>
>     <head>
>         <script language="javascript" type="text/javascript" 
> src="js/jquery1.6.1.min.js"></script>
>         <script language="javascript" type="text/javascript" 
> src="js/jquery.barchart.min.js"></script>
>         <script language="javascript" type="text/javascript" 
> src="js/barRenderer.min.js"></script>
>         <script language="javascript" type="text/javascript" 
> src="js/categoryAxisRenderer.min.js"></script>
>         <script language="javascript" type="text/javascript" 
> src="js/pointLabels.min.js"></script>
>         <script type="text/javascript">
> <?php
>     $dataArray = array(); 
>     
>     $con=mysqli_connect("localhost","root","","posnic");
>     
>     // set the data column labels (data series names) here
>     $dataArray[] = array('Category', 'Count');
>     
>     //1
>     $result = mysqli_query($con,"SELECT COUNT(*) FROM stock_avail");
>     $row = mysqli_fetch_array($result);
>     $NumProducts = $row[0];
>     $dataArray[] = array('Total Number of Products', $NumProducts);
>     
>     //2
>     $result = mysqli_query($con,"SELECT COUNT(*) FROM stock_sales"); 
> //edit sql here
>     $row = mysqli_fetch_array($result);
>     $Numtemp = $row[0];
>     $dataArray[] = array('Total Sales Transactions', $Numtemp); 
>     
>     //2
>     $result = mysqli_query($con,"SELECT COUNT(*) FROM supplier_details"); 
> //edit sql here
>     $row = mysqli_fetch_array($result);
>     $NumSup = $row[0];
>     $dataArray[] = array('Total number of Suppliers', $NumSup); 
>     
>     //2
>     $result = mysqli_query($con,"SELECT COUNT(*) FROM customer_details"); 
> //edit sql here
>     $row = mysqli_fetch_array($result);
>     $NumCus = $row[0];
>     $dataArray[] = array('Total Number of Customers:', $NumCus); 
>     
>     $json = json_encode($dataArray, JSON_NUMERIC_CHECK);
> ?>
>             google.load("visualization", "1", {packages:["corechart"]});
>             google.setOnLoadCallback(drawChart);
>             function drawChart() {
>                 var data = google.visualization.arrayToDataTable(<?php 
> echo $json; ?>);
>
>                 var options = {
>                     title: 'Company Performance',
>                     hAxis: {
>                         title: 'Year',
>                         titleTextStyle: {
>                             color: 'red'
>                         }
>                     }
>                 };
>
>                 var chart = new 
> google.visualization.ColumnChart(document.getElementById('chart_div'));
>                 chart.draw(data, options);
>             }
>         </script>
>     </head>
>     <body>
>         <div id="chart_div" style="height:200px;width:800px;"></div>
>     </body>
> </html>
>
>
>
> On Monday, June 16, 2014 12:19:44 PM UTC-4, Lim Jing Xiang wrote:
>>
>> can anyone teach me how to change google colume chart with php and mysql? 
>> I have no idea :(
>>
>> The graph.php is the file I created before and it link to the database. I 
>> wish to convert it in to the google column chart anyone help??
>>
>> <html>
>>   <head>
>>     <script type="text/javascript" 
>> src="https://www.google.com/jsapi";></script>
>>     <script type="text/javascript">
>>       google.load("visualization", "1", {packages:["corechart"]});
>>       google.setOnLoadCallback(drawChart);
>>       function drawChart() {
>>         var data = google.visualization.arrayToDataTable([
>>           ['Year', 'Sales', 'Expenses'],
>>           ['2004',  1000,      400],
>>           ['2005',  1170,      460],
>>           ['2006',  660,       1120],
>>           ['2007',  1030,      540]
>>         ]);
>>
>>         var options = {
>>           title: 'Company Performance',
>>           hAxis: {title: 'Year', titleTextStyle: {color: 'red'}}
>>         };
>>
>>         var chart = new 
>> google.visualization.ColumnChart(document.getElementById('chart_div'));
>>         chart.draw(data, options);
>>       }
>>     </script>
>>   </head>
>>   <body>
>>     <div id="chart_div" style="width: 900px; height: 500px;"></div>
>>   </body>
>> </html>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Reply via email to