简体   繁体   中英

Using Google charts with php data?

I've got a page in which i display some stats for various arrays passed from my contoller which are contained and displayed using $var1[0] -> amount , i have 3 different arrays which are all similar

$var1[0] -> amount
$var2[0] -> amount
$var3[0] -> amount

all of these relate to a figure pulled from different database tables and can be echo'd to display the figure.

i want to be able to get that number into the google chart to show pretty colours and a % but I'm having trouble porting the numbers into the charts.

i've tried

$data = array( 

             array('Type', 'Amount'),  

             array('HMRC', $hmrc[0] -> amount),  

             array('Apps', $apps[0] -> amount),

             array('Cheques',$cheques[0] -> amount) 

);



json_encode($data);

and then passing the $data into the google.visualization.arrayToDataTable without success.

is there a correct/official way to do this properly?

 var data = google.visualization.arrayToDataTable(
        "<?php echo $data ?>"
        ];

Google has a great example of how to get server side code into the Google Charts here . Instead of the call you have, you should use this one:

var data = new google.visualization.DataTable(<?php echo json_encode($data); ?>);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM