Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image-charts replacement #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
PHP Object wrapper for the Google Chart API
> Google Image Charts API is **deprecated in 2012** and was **turned off on March 18, 2019**. This fork use [Image-Charts.com](https://www.image-charts.com) API instead.


PHP Object wrapper for the ~Google Chart~ [Image-Charts](https://www.image-charts.com) API
===========================================
A simple PHP Object wrapper for the <a href="http://code.google.com/apis/chart/image_charts.html">Google Chart API</a>. Should help anyone who needs to automate the building of the Google Chart url. Supports (almost) all types of charts.

A simple PHP Object wrapper for the [Image-Charts API](https://www.image-charts.com) (a drop-in-replacement and backward compatible chart API with [Google Image-Charts](http://code.google.com/apis/chart/image_charts.html)). Should help anyone who needs to automate the building of the Chart url. Supports (almost) all types of charts.

Prerequisites
-------------
To use this API, you should have a little PHP experience; a little patience to read the documentation; and a little persistence to keep trying if your first charts don't look as you expect them to.
Expand All @@ -14,14 +19,14 @@ Use the master branch for stable release, the experimental branch for the develo

Pie Chart Example
-----------------
<img src="http://chart.apis.google.com/chart?cht=p&chs=350x200&chd=t:112,315,66,40&chdl=first|second|third|fourth&chco=ff3344,11ff11,22aacc,3333aa&chl=first|second|third|fourth&image.png"/>
<img src="https://image-charts.com/chart?cht=p&chs=350x200&chd=t:112,315,66,40&chdl=first|second|third|fourth&chco=ff3344,11ff11,22aacc,3333aa&chl=first|second|third|fourth&chof=.png"/>

Pie chart using the gPieChart class generated by this code:

$piChart = new gPieChart();
// or if you installed via composer
// $piChart = new gchart\gPieChart();

$piChart->addDataSet(array(112,315,66,40));
$piChart->setLabels(array("first", "second", "third","fourth"));
$piChart->setLegend(array("first", "second", "third","fourth"));
Expand All @@ -34,16 +39,16 @@ Installation via Composer
To install using the Composer framework, first install Composer:

curl -s https://getcomposer.org/installer | php


Create a composer.json file in your project root:

{
"require": {
"gchartphp/gchartphp": "dev-master"
}
}

Then run the install:

php composer.phar install
Expand Down
22 changes: 11 additions & 11 deletions gchart/gChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class gChart
* @var string
* @usedby getUrl()
*/
private $baseUrl = "chart.apis.google.com/chart?";
private $baseUrl = "image-charts.com/chart?";

/**
* @brief Data set values.
Expand Down Expand Up @@ -257,14 +257,14 @@ private function simpleEncodeData($data)
* @brief Specifies the style of an axis.
*
* @param $axisIndex Integer This is a zero-based index into the axis array specified by setVisibleAxes
* @param $axisStyle String You can specify the font size, color, and alignment for axis labels, both custom labels and
* default label values. All labels on the same axis have the same format. If you have multiple
* copies of an axis, you can format each one differently. You can also specify the format of a
* @param $axisStyle String You can specify the font size, color, and alignment for axis labels, both custom labels and
* default label values. All labels on the same axis have the same format. If you have multiple
* copies of an axis, you can format each one differently. You can also specify the format of a
* label string, for example to show currency symbols or trailing zeroes.
* By default, the top and bottom axes do not show tick marks by the values, while the left and
* By default, the top and bottom axes do not show tick marks by the values, while the left and
* right axes do show them.
*
* Refer to official documentation at:
* Refer to official documentation at:
* http://code.google.com/apis/chart/image/docs/gallery/bar_charts.html#axis_labels
*/
public function addAxisStyle($axisIndex, $axisStyle)
Expand All @@ -275,18 +275,18 @@ public function addAxisStyle($axisIndex, $axisStyle)
* @brief Specifies the style of an axis.
*
* @param $axisIndex Integer This is a zero-based index into the axis array specified by setVisibleAxes
* @param $axisTickLength Integer You can specify long tick marks for specific axes. Typically this is
* used to extend a tick mark across the length of a chart. Use the addAxisStyle()
* @param $axisTickLength Integer You can specify long tick marks for specific axes. Typically this is
* used to extend a tick mark across the length of a chart. Use the addAxisStyle()
* method to change the tick mark color.
*
* Refer to official documentation at:
* Refer to official documentation at:
* http://code.google.com/apis/chart/image/docs/gallery/bar_charts.html#axis_labels
*/
public function addAxisTickMarkStyle($axisIndex, $axisTickLength)
{
$this->setProperty('chxtc', $axisIndex.','.$this->encodeData($axisTickLength, '|'), true);
}
/*
/*
* Extended Text.
*
* This specifies integer values from 0-4095, inclusive, encoded by two alphanumeric characters.
Expand Down Expand Up @@ -747,7 +747,7 @@ public function renderImage($post = false) {
header('Content-type: image/png');
if ($post) {
$this->setDataSetString();
$url = 'http://chart.apis.google.com/chart?chid=' . md5(uniqid(rand(), true));
$url = 'http://image-charts.com/chart?chid=' . md5(uniqid(rand(), true));
$context = stream_context_create(
array('http' => array(
'method' => 'POST',
Expand Down