2017 © Pedro Peláez
 

library echarts-php

A php wrapper for echarts javascript libraries

image

hisune/echarts-php

A php wrapper for echarts javascript libraries

  • Monday, March 5, 2018
  • by hisune
  • Repository
  • 12 Watchers
  • 171 Stars
  • 72,945 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 40 Forks
  • 0 Open issues
  • 13 Versions
  • 8 % Grown

The README.md

Echarts-PHP

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require, (*1)

Echarts-PHP is a PHP library that works as a wrapper for the Echarts js library (https://github.com/apache/echarts). Support Apache ECharts (incubating) from version 2.2.x to 5.x., (*2)

Welcome star ⭐️!, (*3)

Setup

The recommended way to install Echarts-PHP is through Composer. Just run the composer command to install it:, (*4)

composer require hisune/echarts-php

Table of Contents

Usage

Simple, recommend using PHP property

public ECharts::__construct([string] $dist = '') - Param dist is your customer dist url., (*5)

// The most simple example
use Hisune\EchartsPHP\ECharts;
$chart = new ECharts();
$chart->tooltip->show = true;
$chart->legend->data[] = '销量';
$chart->xAxis[] = array(
    'type' => 'category',
    'data' => array("衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子")
);
$chart->yAxis[] = array(
    'type' => 'value'
);
$chart->series[] = array(
    'name' => '销量',
    'type' => 'bar',
    'data' => array(5, 20, 40, 10, 10, 20)
);
echo $chart->render('simple-custom-id');

Add series with property

void ECharts::addSeries(\Hisune\EchartsPHP\Doc\IDE\Series $series), (*6)

use \Hisune\EchartsPHP\Doc\IDE\Series;
$series = new Series();
$series->type = 'map';
$series->map = 'world';
$series->data = array(
    array(
        'name' => 'China',
        'value' => 100,
    )
);
$series->label->emphasis->textStyle->color = '#fff';
$series->roam = true;
$series->scaleLimit->min = 1;
$series->scaleLimit->max = 5;
$series->itemStyle->normal->borderColor = '#F2EFF4';
$series->itemStyle->normal->areaColor = '#993399';
$series->itemStyle->emphasis->areaColor = '#993399';
$chart->addSeries($series);

Add XAxis with property

void ECharts::addXAxis(\Hisune\EchartsPHP\Doc\IDE\XAxis $xAxis), (*7)

use Hisune\EchartsPHP\Doc\IDE\XAxis;
$xAxis = new XAxis();
$xAxis->type = 'category';
$xAxis->data = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
$chart->addXAxis($xAxis);

Add YAxis with property

void ECharts::addYAxis(\Hisune\EchartsPHP\Doc\IDE\YAxis $yAxis), (*8)

use Hisune\EchartsPHP\Doc\IDE\YAxis;
$yAxis = new YAxis();
$yAxis->type = 'value';
$chart->addYAxis($yAxis);

Or you can set option array directly

void ECharts::setOption(array $option) - Param option is ECharts option array to be set., (*9)

array|string ECharts::getOption([array] $render = null, [boolean] $jsObject = false) - Param render is ECharts option array. - Param jsObject is whether or not to return json string, return PHP array by default., (*10)

$option = array (
  'tooltip' =>
  array (
    'show' => true,
  ),
  'legend' =>
  array (
    'data' =>
    array (
      0 => '销量',
    ),
  ),
  // ...
)
$chart->setOption($option);

Array key support

$chart->legend->data[] = '销量';
$chart->yAxis[0] = array('type' => 'value');

Empty object assignment

If you need to assign a value to an empty object, you can use StdClass, for example: $chart->yAxis = new \StdClass;, (*11)

Javascript function

string Config::jsExpr(string $string), (*12)

// With 'function' letter startup
'axisLabel' => array(
    // this array value will automatic conversion to js callback function
    'formatter' => "
        function (value)
        {
            return value + ' °C'
        }
    "
)

```php // Or you can add any js expr with jsExpr use \Hisune\EchartsPHP\Config; 'backgroundColor' => Config::jsExpr(' new echarts.graphic.RadialGradient(0.5, 0.5, 0.4, [{ offset: 0, color: "#4b5769" }, { offset: 1, color: "#404a59" }]) ');, (*13)

### Customer JS variable name
`void ECharts::setJsVar(string $name = null)`
 - Param `name` is your customer js variable name. By default, js variable name will generate by random.  

`string ECharts::getJsVar()`
```php
$chart->setJsVar('test');
echo $chart->getJsVar(); // echo test
// var chart_test = echarts.init( ...

Customer attribute

string ECharts::render(string $id, [array] $attribute = [], [string] $theme = null) - Param id is your html dom ID. - Param attribute is your html dom attribute. - Param theme is your ECharts theme. - Return html string., (*14)

$chart->render('simple-custom-id2', array('style' => 'height: 500px;'));

Events (for 3.x+)

void ECharts::on(string $event, string $callback) - Param event is event name, available: click, dblclick, mousedown, mousemove, mouseup, mouseover, mouseout - Param callback is event callback., (*15)

string Config::eventMethod(string $name) - Param name is your js function name which to be run in event callback. - Return js string, eg: Config::eventMethod('test') => test(params);, (*16)

use \Hisune\EchartsPHP\Config;
// Recommend standard
$chart->on('click', Config::eventMethod('console.log'));
// Or write js directly
$chart->on('mousedown', 'console.log(params);');

Customer dist

Hisune\EchartsPHP\Config::$dist = 'your dist url';

Dist type

\Hisune\EchartsPHP\Config::$distType = 'common'; // '' or 'common' or 'simple'

Whether or not load minify js file

\Hisune\EchartsPHP\Config::$minify = false; // default is true

Add extra script from cdn

string Config::addExtraScript(string $file, [string] $dist = null) - Param file is your extra script filename. - Param dist is your dist CDN uri., (*17)

Hisune\EchartsPHP\Config::addExtraScript('extension/dataTool.js'); // the second param is your customer dist url

The example for ECharts theme use addExtraScript

use \Hisune\EchartsPHP\Config;
Config::addExtraScript('vintage.js', 'http://echarts.baidu.com/asset/theme/');
echo $chart->render('simple-custom-id', array(), 'vintage');

Full Echarts PHPDoc

For more detail visit: https://hisune.com/view/50/echarts-php-property-phpdoc-auto-generate, (*18)

Demos

https://demo.hisune.com/echarts-php/, (*19)

demo, (*20)

All the Echarts live demos present on https://echarts.apache.org/, (*21)

License

MIT, (*22)

The Versions

05/03 2018

dev-master

9999999-dev http://hisune.com

A php wrapper for echarts javascript libraries

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

echarts php javascript charts

05/03 2018

1.0.12

1.0.12.0 http://hisune.com

A php wrapper for echarts javascript libraries

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

echarts php javascript charts

27/02 2018

1.0.11

1.0.11.0 http://hisune.com

A php wrapper for echarts javascript libraries

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

echarts php javascript charts

31/03 2017

1.0.10

1.0.10.0 http://hisune.com

A php wrapper for echarts javascript libraries

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

echarts php javascript charts

29/03 2017

1.0.9

1.0.9.0 http://hisune.com

A php wrapper for echarts javascript libraries

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

echarts php javascript charts

27/03 2017

1.0.8

1.0.8.0 http://hisune.com

A php wrapper for echarts javascript libraries

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

echarts php javascript charts

23/03 2017

1.0.7

1.0.7.0 http://hisune.com

A php wrapper for echarts javascript libraries

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

echarts php javascript charts

12/09 2016

1.0.6

1.0.6.0 http://hisune.com

A php wrapper for echarts javascript libraries

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

echarts php javascript charts

14/03 2016

1.0.5

1.0.5.0 http://hisune.com

A php wrapper for echarts javascript libraries

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

echarts php javascript charts

04/02 2016

1.0.4

1.0.4.0 http://hisune.com

A php wrapper for echarts javascript libraries

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

echarts php javascript charts

25/11 2015

1.0.3

1.0.3.0 http://hisune.com

A php wrapper for echarts javascript libraries

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

echarts php javascript charts

18/08 2015

1.0.2

1.0.2.0 http://hisune.com

A php wrapper for echarts javascript libraries

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

echarts php javascript charts

03/07 2015

1.0.1

1.0.1.0 http://hisune.com

A php wrapper for echarts javascript libraries

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

echarts php javascript charts