From 36e8438c236d0928871d33324e15115d45d8c6eb Mon Sep 17 00:00:00 2001 From: Cem Ezgin Date: Fri, 5 Apr 2019 12:02:11 +0300 Subject: [PATCH 1/3] Change deprecate google chart api. --- README.md | 40 +--- gchart/gChart.php | 40 +--- gchart/gChartExample.php | 458 +++++++++++++++++++++++++++++++++++++++ gchart/gFunnelChart.php | 24 -- 4 files changed, 465 insertions(+), 97 deletions(-) create mode 100644 gchart/gChartExample.php delete mode 100644 gchart/gFunnelChart.php diff --git a/README.md b/README.md index 7af77ec..62e6119 100644 --- a/README.md +++ b/README.md @@ -19,49 +19,17 @@ Pie Chart Example 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->setLabels = array("first", "second", "third","fourth"); $piChart->setLegend(array("first", "second", "third","fourth")); - $piChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa")); - echo $piChart->getImgCode(); - - -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 - -Then add this line to your application’s index.php file: - - setColors = array("ff3344", "11ff11", "22aacc", "3333aa"); Notes ----- - * The version that was first committed to GITHub is the same that the one on Google Code. Future commits will be reserved to GITHub. + * The verion that was first committed to GUTHub is the same that is on Google Code. Future commits will be reserved to GITHub. * I am pleased with how the code is shaping up. I haven't had much of an opportunity in the past to play with inheritence and polymorphism in PHP. Change Log ---------- 20110903 - Fixed encodeData2 bug in gChart.php -20110816 - PEAR branch merged in master. Legacy branch created with the old files +20110816 - PEAR branch merged in master. Legacy branch created with the old files \ No newline at end of file diff --git a/gchart/gChart.php b/gchart/gChart.php index 9fe08ff..075b2a1 100644 --- a/gchart/gChart.php +++ b/gchart/gChart.php @@ -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. @@ -254,40 +254,7 @@ private function simpleEncodeData($data) return $encodedData; } /** - * @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 - * 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 - * right axes do show them. - * - * Refer to official documentation at: - * http://code.google.com/apis/chart/image/docs/gallery/bar_charts.html#axis_labels - */ - public function addAxisStyle($axisIndex, $axisStyle) - { - $this->setProperty('chxs', $axisIndex.','.$this->encodeData($axisStyle, '|'), true); - } - /** - * @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() - * method to change the tick mark color. - * - * 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. + * @brief Encodes the data as Extended Text. * * This specifies integer values from 0-4095, inclusive, encoded by two alphanumeric characters. * @@ -491,7 +458,6 @@ public function setTitle($title) { $title = str_replace("\r\n", "|", $title); $title = str_replace(" ", "+", $title); - $this->setProperty('chtt', $title); } /** * @brief Sets font size and color of the title @@ -718,7 +684,7 @@ public function getUrl() { $parms[] = $key.'='.$value; } - return $fullUrl.implode('&', $parms); + return $fullUrl.implode('&', $parms); } /** diff --git a/gchart/gChartExample.php b/gchart/gChartExample.php new file mode 100644 index 0000000..9a36794 --- /dev/null +++ b/gchart/gChartExample.php @@ -0,0 +1,458 @@ + + + +PHP Wrapper for Google Chart API Examples - 0.5 + + + + +

PHP Wrapper for Google Chart API Examples - 0.5

+

Quick examples.

+ + +

Pie Chart

+addDataSet(array(112,315,66,40)); +$piChart->setLegend(array("first", "second", "third","fourth")); +$piChart->setLabels(array("first", "second", "third","fourth")); +$piChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa")); +?> +
pie chart using the gPieChart class. +

+code:
+ +$piChart = new gPieChar();
+$piChart->addDataSet(array(112,315,66,40));
+$piChart->setLegend(array("first", "second", "third","fourth"));
+$piChart->setLabels(array("first", "second", "third","fourth"));
+$piChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
+
+

+

3D Pie Chart

+addDataSet(array(112,315,66,40)); +$pie3dChart->setLegend(array("first", "second", "third","fourth")); +$pie3dChart->setLabels(array("first", "second", "third","fourth")); +$pie3dChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa")); +?> +
3D pie chart using the gPieChart class. +

+code:
+ +$pie3dChart = new gPie3DChart();
+$pie3dChart->addDataSet(array(112,315,66,40));
+$pie3dChart->setLegend(array("first", "second", "third","fourth"));
+$pie3dChart->setLabels(array("first", "second", "third","fourth"));
+$pie3dChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
+
+

+

Concentric Pie Chart

+addDataSet(array(112,315,66,40)); +$CPChart->addDataSet(array(100,235,346,50)); +$CPChart->addColors(array("008800", "880000")); +$CPChart->addColors(array("000088", "888800")); +$CPChart->addLegend(array('1', '2', '3', '4')); +$CPChart->addLegend(array('1a', '2a', '3a', '4a')); + +?> +
pie chart using the gPieChart class. +

+code:
+ +$CPChart = new gConcentricPieChart();
+$CPChart->addDataSet(array(112,315,66,40));
+$CPChart->addDataSet(array(100,235,346,50));
+$CPChart->addColors(array("008800", "880000"));
+$CPChart->addColors(array("000088", "888800"));
+$CPChart->addLegend(array('1', '2', '3', '4'));
+$CPChart->addLegend(array('1a', '2a', '3a', '4a'));
+
+

+

Line Chart

+addDataSet(array(112,315,66,40)); +$lineChart->addDataSet(array(212,115,366,140)); +$lineChart->addDataSet(array(112,95,116,140)); +$lineChart->setLegend(array("first", "second", "third","fourth")); +$lineChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa")); +$lineChart->setVisibleAxes(array('x','y')); +$lineChart->setDataRange(30,400); +$lineChart->addAxisRange(0, 1, 4, 1); +$lineChart->addAxisRange(1, 30, 400); +$lineChart->addBackgroundFill('bg', 'EFEFEF'); +$lineChart->addBackgroundFill('c', '000000'); +?> +
line chart using the gLineChart class. +

+code:
+ +$lineChart = new gLineChart(300,300);
+$lineChart->addDataSet(array(112,315,66,40));
+$lineChart->addDataSet(array(212,115,366,140));
+$lineChart->addDataSet(array(112,95,116,140));
+$lineChart->setLegend(array("first", "second", "third","fourth"));
+$lineChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
+$lineChart->setVisibleAxes(array('x','y'));
+$lineChart->setDataRange(30,400);
+$lineChart->addAxisRange(0, 1, 4, 1);
+$lineChart->addAxisRange(1, 30, 400);
+$lineChart->addBackgroundFill('bg', 'EFEFEF');
+$lineChart->addBackgroundFill('c', '000000');
+
+

+

Line Chart with Strip Fill

+addDataSet(array(112,315,66,40)); +$lineChart->addDataSet(array(212,115,366,140)); +$lineChart->addDataSet(array(112,95,116,140)); +$lineChart->setLegend(array("first", "second", "third","fourth")); +$lineChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa")); +$lineChart->setVisibleAxes(array('x','y')); +$lineChart->setDataRange(30,400); +$lineChart->addAxisLabel(0, array("This", "axis", "has", "labels!")); +$lineChart->addAxisRange(1, 30, 400); +$lineChart->setStripFill('bg',0,array('CCCCCC',0.15,'FFFFFF',0.1)); +?> +
line chart using the gLineChart class. +

+code:
+ +$lineChart = new gLineChart(300,300);
+$lineChart->addDataSet(array(112,315,66,40));
+$lineChart->addDataSet(array(212,115,366,140));
+$lineChart->addDataSet(array(112,95,116,140));
+$lineChart->setLegend(array("first", "second", "third","fourth"));
+$lineChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
+$lineChart->setVisibleAxes(array('x','y'));
+$lineChart->setDataRange(30,400);
+$lineChart->addAxisLabel(0, array("This", "axis", "has", "labels!"));
+$lineChart->addAxisRange(1, 30, 400);
+$lineChart->setStripFill('bg',0,array('CCCCCC',0.15,'FFFFFF',0.1);
+
+

+

Line Chart with Line Fill

+addDataSet(array(112,125,66,40)); +$lineChart->setLegend(array("first")); +$lineChart->setColors(array("ff3344")); +$lineChart->setVisibleAxes(array('x','y')); +$lineChart->setDataRange(30,130); +$lineChart->addAxisRange(0, 1, 4, 1); +$lineChart->addAxisRange(1, 30, 130); +$lineChart->addLineFill('B','76A4FB',0,0); +?> +
line chart using the gLineChart class. +

+code:
+ +$lineChart = new gLineChart(300,300);
+$lineChart->addDataSet(array(112,125,66,40));
+$lineChart->setLegend(array("first"));
+$lineChart->setColors(array("ff3344"));
+$lineChart->setVisibleAxes(array('x','y'));
+$lineChart->setDataRange(30,130);
+$lineChart->addAxisRange(0, 1, 4, 1);
+$lineChart->addAxisRange(1, 30, 130);
+$lineChart->addLineFill('B','76A4FB',0,0);
+
+

+

Line Chart with Grid Lines

+addDataSet(array(112,315,66,40)); +$lineChart->addDataSet(array(212,115,366,140)); +$lineChart->addDataSet(array(112,95,116,140)); +$lineChart->setLegend(array("first", "second", "third","fourth")); +$lineChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa")); +$lineChart->setVisibleAxes(array('x','y')); +$lineChart->setDataRange(0,400); +$lineChart->addAxisRange(0, 1, 4, 1); +$lineChart->addAxisRange(1, 0, 400); +$lineChart->setGridLines(33,10); +?> +
line chart using the gLineChart class. +

+code:
+ +$lineChart = new gLineChart(300,300);
+$lineChart->addDataSet(array(112,315,66,40));
+$lineChart->addDataSet(array(212,115,366,140));
+$lineChart->addDataSet(array(112,95,116,140));
+$lineChart->setLegend(array("first", "second", "third","fourth"));
+$lineChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
+$lineChart->setVisibleAxes(array('x','y'));
+$lineChart->setDataRange(0,400);
+$lineChart->addAxisRange(0, 1, 4, 1);
+$lineChart->addAxisRange(1, 0, 400);
+$lineChart->setGridLines(33,10);
+
+

+

Grouped Bar Chart

+addDataSet(array(112,315,66,40)); +$barChart->addDataSet(array(212,115,366,140)); +$barChart->addDataSet(array(112,95,116,140)); +$barChart->setColors(array("ff3344", "11ff11", "22aacc")); +$barChart->setLegend(array("first", "second", "third")); +$barChart->setGradientFill('c',0,array('FFE7C6',0,'76A4FB',1)); +$barChart->setAutoBarWidth(); +?> +
grouped bar chart using the gGroupedBarChart class. +

+code:
+ +$barChart = new gBarChart(500,150,'g');
+$barChart->addDataSet(array(112,315,66,40));
+$barChart->addDataSet(array(212,115,366,140));
+$barChart->addDataSet(array(112,95,116,140));
+$barChart->setColors(array("ff3344", "11ff11", "22aacc"));
+$barChart->setLegend(array("first", "second", "third"));
+$barChart->setGradientFill('c',0,array('FFE7C6',0,'76A4FB',1));
+$barChart->setAutoBarWidth();
+
+

+

Horizontal Grouped Bar Chart

+addDataSet(array(112,315,66,40)); +$barChart->addDataSet(array(212,115,366,140)); +$barChart->addDataSet(array(112,95,116,140)); +$barChart->setColors(array("ff3344", "11ff11", "22aacc")); +$barChart->setLegend(array("first", "second", "third")); +$barChart->setGradientFill('c',0,array('FFE7C6',0,'76A4FB',1)); +$barChart->setLegend(array("This", "is", "different")); +?> +
horizontal grouped bar chart using the gGroupedBarChart class. +

+code:
+ +$barChart = new gBarChart(150,500,'g','h');
+$barChart->addDataSet(array(112,315,66,40));
+$barChart->addDataSet(array(212,115,366,140));
+$barChart->addDataSet(array(112,95,116,140));
+$barChart->setColors(array("ff3344", "11ff11", "22aacc"));
+$barChart->setLegend(array("first", "second", "third"));
+$barChart->setGradientFill('c',0,array('FFE7C6',0,'76A4FB',1));
+$barChart->setLegend(array("This", "is", "different"));
+
+

+

Stacked Bar Chart

+addDataSet(array(112,315,66,40)); +$barChart->addDataSet(array(212,115,366,140)); +$barChart->addDataSet(array(112,95,116,140)); +$barChart->setLegend(array("first", "second", "third","fourth")); +$barChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa")); +$barChart->setTitle("A multiline\r\nA Title"); +?> +
stacked bar chart using the gStackedBarChart class. +

+code:
+ +$barChart = new gStackedBarChart(450,350);
+$barChart->addDataSet(array(112,315,66,40));
+$barChart->addDataSet(array(212,115,366,140));
+$barChart->addDataSet(array(112,95,116,140));
+$barChart->setLegend(array("first", "second", "third","fourth"));
+$barChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
+$barChart->setTitle("A multiline\r\nA Title");
+
+

+

Horizontal Stacked Bar Chart

+setHorizontal(true); +$barChart->groupSpacerWidth = 10; +?> +
horizontal stacked bar chart using the gStackedBarChart class. +

+code:
+ +$barChart->setHorizontal(true);
+$barChart->groupSpacerWidth = 10; +
+

+

Venn Diagram

+setSizes(1120,3150); +$vennDiagram->setIntersections(220, 320); +$vennDiagram->setEncodingType('s'); +$vennDiagram->setColors(array("ff3344", "11ff11", "22aacc", "3333aa")); +?> +
venn diagram using the gVennDiagram class. +

+code:
+ +$vennDiagram = new gVennDiagram();
+$vennDiagram->setSizes(1120,3150);
+$vennDiagram->setIntersections(220, 320);
+$vennDiagram->setEncodingType('s');
+$vennDiagram->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
+
+

+

Venn Diagram

+setSizes(20, 20, 20); +$vennDiagram->setIntersections(0, 4, 6, 2); +$vennDiagram->setColors(array("ff3344", "11ff11", "22aacc", "3333aa")); +?> +
venn diagram using the gVennDiagram class. +

+code:
+ +$vennDiagram = new gVennDiagram();
+$vennDiagram->setSizes(10, 10, 10);
+$vennDiagram->setIntersections(2, 2, 2, 1);
+$vennDiagram->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
+
+

+

Latex Formula

+ setLatexCode('\cos(x)^2+\sin(x)^2=1'); +?> +
latex formula using the gFormula class. +

+code:
+ +$latex = new gFormula();
+$latex -> setLatexCode('\cos(x)^2+\sin(x)^2=1');
+
+

+

QR Code

+ setQRCode('gChartPhp is awesome!'); +?> +
QR Code using the gQRCode class. +

+code:
+ +$qr = new gQRCode();
+$qr -> setQRCode('gChartPhp is awesome!');
+
+

+

Google-o-Meter

+ addDataSet(array(10, 50, 90)); +$meter -> setColors(array('FFFFFF','000000')); +?> +
Goole-o-Meter Chart using the gMeterChart class. +

+code:
+ +$meter = new gMeterChart();
+$meter -> addDataSet(array(10, 50, 90));
+$meter -> setColors('FFFFFF','000000');
+
+

+

Map Chart

+ setZoomArea('usa'); +$map -> setStateCodes(array('CA', 'TX', 'NY', 'UT', 'NV')); +$map -> addDataSet(array(23, 32, 12, 54, 23)); +$map -> setColors('342544', array('BE3481','34BE12')); +?> +
Map Chart using the gMapChart class. +

+code:
+ +$map = new gMapChart();
+$map -> setZoomArea('usa');
+$map -> setStateCodes(array('CA', 'TX', 'NY', 'UT', 'NV'));
+$map -> addDataSet(array(23, 32, 12, 54, 23));
+$map -> setColors('342544', array('BE3481','34BE12'));
+
+

+

Scatter Chart

+ addDataSet(array(12,87,75,41,23,96,68,71,34,9)); +$scatter -> addDataSet(array(98,60,27,34,56,79,58,74,18,76)); +$scatter -> addValueMarkers('d','FF0000',0,-1,15); +$scatter -> setVisibleAxes(array('x','y')); +$scatter -> addAxisRange(0, 0, 100); +$scatter -> addAxisRange(1, 0, 100); +?> +
Map Chart using the gMapChart class. +

+code:
+ +$scatter = new gScatterChart();
+$scatter -> addDataSet(array(12,87,75,41,23,96,68,71,34,9));
+$scatter -> addDataSet(array(98,60,27,34,56,79,58,74,18,76));
+$scatter -> addValueMarkers('d','FF0000',0,-1,15);
+$scatter -> setVisibleAxes(array('x','y'));
+$scatter -> addAxisRange(0, 0, 100);
+$scatter -> addAxisRange(1, 0, 100);
+
+

+

Grouped Bar Chart

+addDataSet(array(0,10,20,30,20,70,80)); +$barChart->addDataSet(array(0,20,10,5,20,30,10)); +$barChart->addHiddenDataSet(array(10,0,20,15,60,40,30)); +$barChart->addValueMarkers('D','76A4FB',2,0,3); +$barChart->setAutoBarWidth(); +?> +
compound bar chart using the gGroupedBarChart class and addValueMarkers(). +

+code:
+ +$barChart = new gBarChart(250,250,'s');
+$barChart->addDataSet(array(0,10,20,30,20,70,80));
+$barChart->addDataSet(array(0,20,10,5,20,30,10));
+$barChart->addHiddenDataSet(array(10,0,20,15,60,40,30));
+$barChart->addValueMarkers('D','76A4FB',2,0,3);
+$barChart->setAutoBarWidth();
+
+

+

Candlestick Chart

+ addDataSet(array(90,80,70,50,40,30,20,10)); +$candlestick -> addHiddenDataSet(array(0,5,10,0,5,10,0)); +$candlestick -> addHiddenDataSet(array(2,15,20,5,15,40,0)); +$candlestick -> addHiddenDataSet(array(5,35,20,2,35,20,0)); +$candlestick -> addHiddenDataSet(array(15,40,30,15,40,50,0)); +$candlestick -> addValueMarkers('F','000000',1,'1:-2',20); +$candlestick -> setVisibleAxes(array('y')); +$candlestick -> addAxisRange(0, 0, 100); +?> +
compound bar chart using the gGroupedBarChart class and addValueMarkers(). +

+code:
+ +$candlestick = new gLineChart(200,125);
+$candlestick -> addDataSet(array(90,80,70,50,40,30,20,10));
+$candlestick -> addHiddenDataSet(array(0,5,10,0,5,10,0));
+$candlestick -> addHiddenDataSet(array(2,15,20,5,15,40,0));
+$candlestick -> addHiddenDataSet(array(5,35,20,2,35,20,0));
+$candlestick -> addHiddenDataSet(array(15,40,30,15,40,50,0));
+$candlestick -> addValueMarkers('F','000000',1,'1:-2',20);
+$candlestick -> setVisibleAxes(array('y'));
+$candlestick -> addAxisRange(0, 0, 100);
+
+

+ + diff --git a/gchart/gFunnelChart.php b/gchart/gFunnelChart.php deleted file mode 100644 index e1ef795..0000000 --- a/gchart/gFunnelChart.php +++ /dev/null @@ -1,24 +0,0 @@ -setChartType('s', 'h'); - $this->setDimensions($width, $height); - } - - /** - * This function creates the funnel effect by calculating the hidden dataset - * - */ - public function addData($data) - { - $ghost = array(); - for($i = 0; $i < count($data); $i++) { - $ghost[$i] = (100 - $data[$i])/2; - } - $this->addDataSet($ghost); - $this->addDataSet($data); - } -} \ No newline at end of file From 3c92d36bf6603fa9e782a218a896f4f8aa78e24d Mon Sep 17 00:00:00 2001 From: Cem Ezgin Date: Fri, 5 Apr 2019 16:08:50 +0300 Subject: [PATCH 2/3] Change camelcase name to flat. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index be33971..9495566 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "gChartPhp/gChartPhp", + "name": "gchartphp/gchartphp", "description": "PHP Object wrapper for the Google Chart API.", "keywords": ["Google Charts", "wrapper", "php", "charts"], "homepage": "https://github.com/pacbard/gChartPhp", From 2bcaa72afdfed5d7f2c59eca38ea393b1987a231 Mon Sep 17 00:00:00 2001 From: Busra Gumusel Date: Tue, 9 Apr 2019 15:44:59 +0300 Subject: [PATCH 3/3] Change link from readme. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 62e6119..39a1419 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ PHP Object wrapper for the Google Chart API =========================================== -A simple PHP Object wrapper for the Google Chart API. 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 Google Chart API. Should help anyone who needs to automate the building of the Google 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. @@ -32,4 +32,4 @@ Notes Change Log ---------- 20110903 - Fixed encodeData2 bug in gChart.php -20110816 - PEAR branch merged in master. Legacy branch created with the old files \ No newline at end of file +20110816 - PEAR branch merged in master. Legacy branch created with the old files