ipmedia/google-chart-wrapper

此包最新版本(1.0.0)没有可用的许可证信息。

基于 http://chart.apis.google.com/chart 的 PHP 包装器

1.0.0 2016-08-11 07:02 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:58:27 UTC


README

Build Status

简介

GoogleChartWrapper 是一个在 Google Image Chart Service 上方的快速、简洁的 API。

警告: 此 API 已弃用。

尽管此 API 已弃用,且可能随时关闭,但当你需要快速为电子邮件报告生成图表时,它仍然是一个不错的选择。请随意按你喜欢的方式改进它。

安装

composer require ipmedia/google-chart-wrapper

用法

use \IpMedia\GoogleChartWrapper;

// instantiate wrapper
$wrapper = new GoogleChartWrapper;

// set the data to be rendered
$wrapper->setData([ 5, 2, 3 ]);

// render the link to the google api generator
$wrapper->getSrc();  // http://chart.apis.google.com/chart?cht=p3&chs=450x200&chd=t:5,2,3

// change the type of the chart
$wrapper->setType(GoogleChartWrapper::PIE)->getSrc();  // http://chart.apis.google.com/chart?cht=p&chs=450x200&chd=t:5,2,3

// set the size of the chart
$wrapper->setSize(200, 200)->$this->getSrc();  // http://chart.apis.google.com/chart?cht=p3&chs=200x200&chd=t:5,2,3

// set the base color
$wrapper->setBaseColor('00ffff')->getSrc(); // http://chart.apis.google.com/chart?cht=p3&chs=450x200&chd=t:5,2,3&chco=00ffff
// rgb supported
$wrapper->setBaseColor([ 0, 255, 255 ])->getSrc(); // http://chart.apis.google.com/chart?cht=p3&chs=450x200&chd=t:5,2,3&chco=00ffff

// set the base color
$wrapper->setGradientColor([ 0, 0, 0 ], [ 255, 255, 255 ])->getSrc(); // http://chart.apis.google.com/chart?cht=p3&chs=450x200&chd=t:5,2,3&chco=000000,ffffff

// or set a color for each segment
$this->setColors([ [ 255, 0, 0 ], [ 0, 255, 0 ], [ 0, 0, 255 ] ])->getSrc(); // http://chart.apis.google.com/chart?cht=p3&chs=450x200&chd=t:5,2,3&chco=ff0000|00ff00|0000ff

// add labels
$wrapper->setLabels([ 'Five', 'Two', 'Four' ])->getSrc();  // http://chart.apis.google.com/chart?cht=p3&chs=450x200&chd=t:5,2,3&chl=Five|Two|Four

// and finally you can set the labels of the chart 
$wrapper->setTitle('Chart Title')->getSrc();  // http://chart.apis.google.com/chart?cht=p3&chs=450x200&chd=t:5,2,3&chtt=Chart+Title

许可证

GoogleChartWrapper 是开源软件,采用 MIT 许可证