Skip to content

Instantly share code, notes, and snippets.

@doctea
Created March 12, 2019 10:56
Show Gist options
  • Save doctea/34947c7b09b378f6a595effdaa98054b to your computer and use it in GitHub Desktop.
Save doctea/34947c7b09b378f6a595effdaa98054b to your computer and use it in GitHub Desktop.
Script to draw Google charts API and image-charts output side-by-side to compare differences
<?php
/**
used for dev/testing in conjunction with https://gist.github.com/doctea/134fa35dd359380071ad426377d28cc5
*/
if (!function_exists('print_rp')) {
function print_rp($data, $message = "output:") {
?><pre><?php print htmlspecialchars($message) ?><?php print_r($data) ?></pre>
<?php
}
}
function getUrl($params, $API_URL = 'http://chart.apis.google.com/chart') {
//$API_URL = 'http://chart.apis.google.com/chart';
//$API_URL = 'https://image-charts.com/chart'; // Tristan3dtotal for https://devwiki.3dtotal.com/problem:shop.3dtotal.com:adminhtml:dashboard_graph_fails_to_load_503_tunnel_unable_to_read_response_or_response_is_empty
$p = array();
foreach ($params as $name => $value) {
$p[] = $name . '=' .urlencode($value);
}
return $API_URL . '?' . implode('&', $p);
}
?>
<h1>Test graph!</h1><?php
$input = $_REQUEST['input'];
if ($input=="") {
$input=<<<EOD
array (
'cht' => 'lc',
'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0',
'chm' => 'B,f4d4b2,0,0,0',
'chco' => 'db4814',
'chd' => 'e:jTYthcgCb.YjdalJmPfy68AA',
'chxt' => 'x,y',
'chxl' => '0:||02/2018||05/2018||08/2018||10/2018||12/2018||02/2019|1:|0|10000|20000|30000|40000|50000',
'chs' => '587x300',
'chg' => '9.0909090909091,20,1,0',
);
EOD;
}
?>
<form>
<textarea cols=140 rows=20 name="input"><?php print htmlspecialchars($input) ?></textarea>
<input type="submit" />
</form>
<?php
eval("\$data = $input;");
print_rp($data, "decoded data:");
$sp = explode(":", $data['chxl']);
$axis_x = explode("|", $sp[1]);
//$axis_x =
array_pop ($axis_x);
$axis_y = explode("|", $sp[2]);
print_rp($axis_x, "Axis X:");
print_rp($axis_y, "Axis Y:");
?>
<hr>
<img src="<?php print getUrl($data) ?>" />
<img src="<?php print getUrl($data, 'http://image-charts.com/chart') ?>" />
<hr>
Done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment