rockys/echarts-php
Composer 安装命令:
composer require rockys/echarts-php
包简介
A php wrapper for echarts javascript libraries
关键字:
README 文档
README
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.
Welcome star ⭐️!
Setup
The recommended way to install Echarts-PHP is through Composer. Just run the composer command to install it:
composer require hisune/echarts-php
Table of Contents
- Class: ECharts
- __construct([string] $dist = '')
- addSeries(Series $series)
- addXAxis(XAxis $xAxis)
- addYAxis(YAxis $yAxis)
- setOption(array $option)
- getOption([array] $render = null, [boolean] $jsObject = false)
- setJsVar(string $name = null)
- getJsVar()
- render(string $id, [array] $attribute = [], [string] $theme = null)
- on(string $event, string $callback)
- Class: Config
- Theme
- PHPDoc for property
Usage
Simple, recommend using PHP property
public ECharts::__construct([string] $dist = '')
- Param
distis your customer dist url.
// 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)
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)
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)
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
optionis ECharts option array to be set.
array|string ECharts::getOption([array] $render = null, [boolean] $jsObject = false)
- Param
renderis ECharts option array. - Param
jsObjectis whether or not to return json string, return PHP array by default.
$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;
Javascript function
string Config::jsExpr(string $string)
// With 'function' letter startup 'axisLabel' => array( // this array value will automatic conversion to js callback function 'formatter' => " function (value) { return value + ' °C' } " )
// 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" }]) ');
Customer JS variable name
void ECharts::setJsVar(string $name = null)
- Param
nameis your customer js variable name. By default, js variable name will generate by random.
string ECharts::getJsVar()
$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
idis your html dom ID. - Param
attributeis your html dom attribute. - Param
themeis your ECharts theme. - Return html string.
$chart->render('simple-custom-id2', array('style' => 'height: 500px;'));
Events (for 3.x+)
void ECharts::on(string $event, string $callback)
- Param
eventis event name, available:click,dblclick,mousedown,mousemove,mouseup,mouseover,mouseout - Param
callbackis event callback.
string Config::eventMethod(string $name)
- Param
nameis your js function name which to be run in event callback. - Return js string, eg: Config::eventMethod('test') => test(params);
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
fileis your extra script filename. - Param
distis your dist CDN uri.
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
Demos
https://demo.hisune.com/echarts-php/
All the Echarts live demos present on https://echarts.apache.org/
License
MIT
rockys/echarts-php 适用场景与选型建议
rockys/echarts-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.79k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 11 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「javascript」 「charts」 「echarts」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rockys/echarts-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rockys/echarts-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rockys/echarts-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
The "View Counter" bundle
A Versatile and Expandable jQuery Plotting Plugin
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
PHP library for c3js
统计信息
- 总下载量: 3.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-14