php-RChart supports retrieving data from Google sheets via method
"rgraph::getsheetsData". You must provide a key of the spreadsheet
created at google sheets and published to the web. As a second parameter you may specify the number of rows
to retrieve (if not specified all rows will be retrieved). If the third parameter is set to true, then the first row's
data will be used as keys for the columns.
<?php
include_once "environment.php";
use phpRGraph\rgraph_chart;
use phpRGraph\rgraph_options;
// rgraph chart
$template = "default.php";
// rgraph chart
$id = "cvs";
$draw_option = "draw();";
$width = "700";
$height = "400";
$chart = new rgraph_chart("cvs", null, "Bar");
$key = "1ncvARBgXaDjzuca9i7Jyep6JTv9kms-bbIzyAxbaT0E";
$sheets_data = $chart->getsheetsData($key, 12, true);
$data = array($sheets_data['Fred'],$sheets_data['Lucy'],
$sheets_data['Lilly']);
$chart->set_data($data);
$chart->rearrangeData();
$options = new rgraph_options("bar_3d.ini");
$options->set_option("title", "Data from Google Sheets");
$options->set_option("xaxisLabels", $sheets_data[0]);
$options->set_option("colorsSequential", false);
$options->set_option("grouping", "stacked");
$options->set_option("key", array("Fred","Lucy","Lilly"));
$options->set_option("keyPositionX",300);
$options->set_option("keyPositionY", 40);
$options->set_tooltip($chart->get_data(), "#key#: #val#
Total #label#: #total#");
$chart->set_options($options);
$rgraph_json = $chart->toString();
$chart_script = "";
$event_script = "";
include_once ($templates . $template);
?>