user389391
user389391

Reputation: 97

PHP array to google chart series array

I have the following php array

Array ( [0] => 
            Array ( [year] => 2009 
                    [month] => January 
                    [month_sales] => 728 
                    [year_totalsales] => 2663 ) 
        [1] => 
            Array ( [year] => 2009 
                    [month] => February 
                    [month_sales] => 640 
                    [year_totalsales] => 2663 ) 
        [2] => 
            Array ( [year] => 2009 
                    [month] => March 
                    [month_sales] => 636 
                    [year_totalsales] => 2663 ) 
        [3] => 
            Array ( [year] => 2010 
                    [month] => January 
                    [month_sales] => 636 
                    [year_totalsales] => 2663 ) 
        [4] => 
            Array ( [year] => 2010 
                    [month] => February 
                    [month_sales] => 23 
                    [year_totalsales] => 2663 ) )

How do I get this to display in Google charts?

Upvotes: 2

Views: 6200

Answers (3)

Gregory
Gregory

Reputation: 207

Beaware that Oliver's answer is for the (static) Image Chart Google API which is being depreciated and not available after 2015. (I didn't have enough rep to comment)

This class is to aid using PHP with the current Google Chart API. I'm yet to use/test them myself but it seems to be straight forward from the examples.

https://code.google.com/p/php-class-for-google-chart-tools/

Upvotes: 2

Oliver M Grech
Oliver M Grech

Reputation: 3171

You will have to loop into your array and generate a pipe delimited string for use in your chart.

I suggets also to read the following

Google Chart Tools & Data Formats

Upvotes: 0

DarkMantis
DarkMantis

Reputation: 1516

There are scripts which google have provided to make this sort of thing much easier.

I hope the following link helps you: http://code.google.com/p/googlechartphplib/wiki/GettingStarted

It's fairly easy from what I've dabbled in, however, you have to be careful as I have made many mistakes doing this and I managed to mess up the data which I was trying to input which then gave me a totally different chart.

I hope this helps though

Upvotes: 1

Related Questions