Skip to content

Commit

Permalink
Update GoogleCharts.php
Browse files Browse the repository at this point in the history
Added new option to print chart as PNG
  • Loading branch information
fruppel committed Nov 10, 2015
1 parent b395ee3 commit 5313b6f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions GoogleCharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class GoogleCharts extends Widget
* classes and functions.
*/
public $visualization = '';

/**
* @var bool $asPng Set it to true and chart will be rendered as PNG. Please note that this is currently only
* possible for core charts and geocharts.
*/
public $asPng = false;

/**
* @throws InvalidConfigException
Expand Down Expand Up @@ -112,16 +118,26 @@ function " . $functionName . "() {";
else
{
$js .= "
var data = new google.visualization.DataTable(" . json_encode($this->data) . ");
";
var data = new google.visualization.DataTable(" . json_encode($this->data) . ");";
}

$js .= "
var chart_div = document.getElementById('googlechart_". $this->getId() . "');
var options = " . $this->options . ";
var chart = new google.visualization." . $this->visualization . "(document.getElementById('googlechart_". $this->getId() . "'));
var chart = new google.visualization." . $this->visualization . "(chart_div);";

if ($this->asPng)
{
$js .= "
google.visualization.events.addListener(chart, 'ready', function () {
chart_div.innerHTML = '<img src=\"' + chart.getImageURI() + '\">';
});";
}

$js .= "
chart.draw(data, options);
}";

$view->registerJs($js, View::POS_HEAD);

if ($this->responsive) {
Expand Down

0 comments on commit 5313b6f

Please sign in to comment.