Prasanna Hegde
Prasanna Hegde

Reputation: 29

google charts api - pie chart is not displaying

I am trying to create a piechart dynamically by using Google Chart api. i am taking values from the database. I am not getting how exactly this can be done.

$resultViewed = $this->model_report_product->getMostViewed();
        $stringResult ="var data= google.visualization.arrayToDataTable([ ['Product', 'Views'],";

     foreach($resultViewed as $results)
     {               
                 $stringResult = $stringResult . "['".$results['name']."',".$results['quantity']."],";
                 break;     
     }
     $stringResult .= "]);";

    $this->data['Viewed'] = $stringResult;  

When i run this, it gives Chart heading but pie chart is not displayed but it says No Data.

Upvotes: 1

Views: 472

Answers (1)

John Moses
John Moses

Reputation: 1283

You can't pass a variable in memory between php to html. You have to print it out to pass it to html. So where you have:

return $stringResult;

you should print it out like:

print $stringResult;

Upvotes: 1

Related Questions