Ok, a couple of things need to be fixed here:

First, you need to include the password in the PDO constructor, even if the 
password is blank, so this line must include the $password variable:

$db = new PDO("mysql:dbname = $mobiledb", $localhost, $password);

Then, for the columns, there are a few valid data types: "string", 
"number", "date", "datetime", "timeofday". "boolean".  If you are using 
"date", "datetime", or "timeofday", chances are that your database output 
will require some modifications before you can add them to the chart data, 
but if you are using the others, you can output them as-is.  Given that you 
chose "varchar" for the types, "string" is likely the most appropriate data 
type for your columns:

array('label' => 'Q1' , 'type' => 'string'),
array('label' => 'Q2' , 'type' => 'string')

On Saturday, November 9, 2013 7:16:35 AM UTC-5, Nelson Idachi wrote:
>
> The problem is my database does not have a password and still its not 
> working. Kindly check to see if there is anything i did not do right
>
>
> <?php 
> $username = 'localhost';
> $password = '';
> $databasename = 'mobiledb';
>
> try {
> $db = new PDO("mysql:dbname = $mobiledb", $localhost, $);
> }
> catch (PDOException $e) {
> die("{error: {$e->getMessage()}}");
> }
> $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
>
> $query = $db->prepare("SELECT Q1, Q2, FROM table2");
> try {
> $query->execute();
> $results = $query->fetchAll(PDO::FETCH_ASSOC);
> }
> catch (PDOException $e) {
> die("{error: {$e->getMessage()}}");
> }
>
> $table = array(
> 'cols' => array(
> array('label' => 'Q1' , 'type' => '<varchar>'),
> array('label' => 'Q2' , 'type' => '<varchar>')
> // etc
> ),
> 'rows' => array()
> );
>
> foreach ($results as $r) {
> $table['rows'][] = array('c' => array(
> array('v' => $r['Q1']),
> array('v' => $r['Q2'])
> // etc
> ));
> }
> ?>
> <!DOCTYPE html>
> <html>
> <head>
> <meta http-equiv="content-type" content="text/html; charset=UTF-8">
> <title>My Chart</title>
> <script type='text/javascript' src="http://www.google.com/jsapi";></script>
> <script type='text/javascript'>
> //<![CDATA[ 
> function drawChart () {
> var data = new google.visualization.DataTable(<?php echo 
> json_encode($table, JSON_NUMERIC_CHECK); ?>);
>  var chart = new 
> google.visualization.LineChart(document.querySelector('#chart_div'));
> chart.draw(data, {
> height: 400,
> width: 600
> });
> }
> google.load('visualization', '1', {packages:['corechart'], callback: 
> drawChart});
> //]]>  
> </script>
> </head>
> <body>
> <div id="chart_div"></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/groups/opt_out.

Reply via email to