1

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.

1

1 Answer 1

1

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; 
Sign up to request clarification or add additional context in comments.

4 Comments

But its giving me no data. can i use php script to get the data from database within javascript like this?
Hi, I have edited the code. Actually i am getting the 1st row of data in my array, rest am not getting. Not getting whats the problem in the loop. Please look at my code which i have edited and help me in this. please please
The for loop is only looping through once and then hitting that break command. Remove the break command.
Ya. sorry. But even after removing the break its the same problem. Just to test i had put the break but even then it displays only one data.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.