This article will show you how to connect Google Sheets with Charts 4 PHP framework

Step 1: Give permission to access Google Spreadsheet

Before proceeding to next step make sure that your google sheet have permission to view :

Goto your My Driver folder and right click on the spreadsheet you want to share. Then select :  “Anyone with the link can view “from dropdown . (See screenshots)

 

 

Step 2: Add your spreadsheet key and sheet name 

Change the key and sheet_name  as given in your spreadsheet with following format :

https://docs.google.com/spreadsheets/d/{key}/gviz/tq?tqx=out:csv&sheet={sheet_name}

in our case, after adding key and sheet name, the url becomes:

https://docs.google.com/spreadsheets/d/1KkNJxvjhpjyzUu-0EW0xmhnYxKN8RPeEqhctxKJkx3s/gviz/tq?tqx=out:csv&sheet=Sheet1

 

Step 3: Include Charts 4 PHP Library

include("../../lib/inc/chartphp_dist.php");
$p = new chartphp();

 

Step 4: Set your google sheet url in a string 

So finally we have this link (saved in url variable) :

$url = "https://docs.google.com/spreadsheets/d/1KkNJxvjhpjyzUu-0EW0xmhnYxKN8RPeEqhctxKJkx3s/gviz/tq?tqx=out:csv&sheet=Sheet1";
$p->data_csv_url = $url;

In our case-example the sheet is:

 

By default , first column (Downloads) and second column (Week 0) are selected (highlighted above). To make charts from other 2 columns, see Documentation.

Also Note that the chart will be made for 2 columns only. More than 2 columns are currently not supported.

Step 4: Set title for the chart

$p->title = "Downloads / Day";

Step 5: Render Chart

$out = $p->render("c1");

Result:


This feature is currently supported in paid version only.

Whats Next:

  • To download latest free version (with limited features), please visit our Download page.
  • To buy full functional paid version with technical support, please visit our Pricing page.
  • For existing paid customers who want to renew/upgrade, please visit Upgrade page.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?