hisune / echarts-php Goto Github PK
View Code? Open in Web Editor NEWEcharts-PHP a PHP library that works as a wrapper for the Echarts js library
Home Page: https://hisune.com/view/38/echarts-php-library
License: MIT License
Echarts-PHP a PHP library that works as a wrapper for the Echarts js library
Home Page: https://hisune.com/view/38/echarts-php-library
License: MIT License
Hi there,
Sorry to barrage you with quesitons:
Can't seem to customize the guage.
$chart1 = new ECharts(); $chart1->tooltip->show = true; $chart1->tooltip->formatter = "{a} <br/>$ {c} "; $chart1->title->text= "Tracking to Goal"; $chart1->title->textStyle = ['align'=>'center']; $chart1->title->subtext ='Last 12 Months 000\'s'; $chart1->series[] = array( 'name' => 'Revenue', 'type' => 'gauge', 'max' => $chart1data['totalbudget'], 'data' => $chart1data['totalsales'], 'show'=> true, 'lineStyle' => array( 'color'=> [[0.2, 'lightgreen'],[0.4, 'orange'],[0.8, 'skyblue'],[1, '#ff4500']], 'width'=> 30, ));
Any idea what I'm doing wrong?
Kind regards
echarts3中只有toolbox.feature.saveAsImage,那是要等图片显示出来后,再手动一个一个另存为图片的。
能否使用代码方式生成图片,我生成的统计图有好多。谢谢!
有一个需求,直接在后台生成echarts的图片,查看echarts文档有一个方法是getDataURL去获取一串base64信息,但你这个Echarts-PHP不知道能不能使用这种方法在后台就直接得到这一串base64字符?
看到源代码是 ECharts 类有一个 setJsVar 方法,但是同个界面有多个 ECharts 实例去渲染的时候 不能自定义js echarts的 init 方法的变量,反而变成了同一个最后自定义的变量了。这个问题导致在 ajax 请求的时候不拿不到自定义的变量去更改图表的数据(getOption())。看到源码是 Config 类的 静态属性 $jsVar 我只能在每次 ECharts 类 渲染数据前 (render()) 去 使用如下代码:
Config::$jsVar = $echarts->getJsVar();
这样每次个 render() 前面都会多这个一句代码,不知道这个算不算是一个小问题哦。
Hi,
I have tried a number of things to resolve this, including having the full echarts.js loaded. Any thoughts?
Hello, if it is possible to generate the graph to put it inside a pdf generated with Fpdf inside the script in php?
how to make it generate a base64 image from php
Thanks and regards
<div id="chart" style="width: 600px; height: 400px;"></div>
<script>
var chartDom = document.getElementById('chart');
var myChart = echarts.init(chartDom);
var option;
option= {"legend":{"right":"right"},"series":[{"name":"\u6570\u636e","type":"pie","radius":"60%","data":[{"value":12,"name":"GO"},{"value":22,"name":"PHP"},{"value":31,"name":"JAVA"}]}]}
// option= {type_dis}
option && myChart.setOption(option);
</script>
咋HTML中写死上面代码确实能生成图片,但是我的需求是到出成PDF文件。导出到文件中后就会是空白。如何转换成png图像呢。我好导出PDF文件
Hi, I'm using composer to install package.
require_once __DIR__ . '/../../vendor/autoload.php';
use Hisune\EchartsPHP\ECharts;
$chart = new ECharts();
another try below, but not working too;
require_once (__DIR__ . '/../../vendor/hisune/echarts-php/src/Config.php');
require_once (__DIR__ . '/../../vendor/hisune/echarts-php/src/ECharts.php');
$chart = new ECharts();
In all cases, I receive "Fatal error: Class 'ECharts' not found" messages, but files exists in vendor/hisune folder and correct config autoload.
my folder structure is:
What I'm doing wrong?
#26 it's about the same issue that was closed:
Finaly I Tried it but still have an issue with it :
i only need to return
tooltip: this.tooltip
without double quotes if i use:
$chart->tooltip = Config::jsExpr('this.tooltip');
it suround the this.tooltip with " and it broke Echarts how to avoid having the double quote added please ?
HI,
I'm using Echart 4 with Angular for the front End, and i'm sending Api Call to A Php Controller That return a json response.
my problem is when i use :
$chart = new ECharts();
$chart->legend->show = false;
when i send back the object $chart i get this:
"tooltip": { "_options": { "show": true, "trigger": "item", } },
the "_options":
surround my data and i dont need that surround how can i get this response without "_options":
so my result will be:
"tooltip": { "show": true, "trigger": "item", },
I have this for all Series also, Can you please show me how
charts not working in chrome but work with firefox !, with error message on console "Uncaught SyntaxError: Unexpected end of input echarts.min.js:1", any help?
Hi,
Trying to make the config work, but I'm not really getting it. I know the code below is wrong, but I'm not getting the syntax?
I have the following for example, curios how Config:: is supposed to be used in a defined chart to make it work?
$chart1 = new ECharts(); $chart1->xAxis->axisLabel =>Config::jsExpr('formatter' => " function (v) { switch (v+''){ case '10': return 'here; case '30': return 'is; case '60': return 'a; case '90': return 'cool'; default: return ''; } " );
Thanks!
Gary
亲,你应该有听过swoole吧,通过swoole把程序变成常驻内存型程序。echarts-php中的config类用了静态变量,导致执行过一次,变量得不到释放,下次请求保留这上一次请求的数据,导致输出图表失败
<?php
include dirname(__DIR__)."/vendor/autoload.php";
use \Hisune\EchartsPHP\ECharts;
use \Hisune\EchartsPHP\Config;
use \Hisune\EchartsPHP\Doc\IDE\Series;
$http = new swoole_http_server("0.0.0.0", 9501, SWOOLE_BASE);
$http->set([
]);
$http->on('request', function ($req, $resp) {
$data = '{"tooltip":{"trigger":"axis"},"yAxis":[{"name":"\u6570\u503c","type":"value","axisLabel":{"formatter":"{value}"}}],"xAxis":[{"type":"category","data":["2018-12-03","2018-12-04","2018-12-05","2018-12-06","2018-12-07","2018-12-08(\u5468\u516d)","2018-12-09(\u5468\u65e5)"],"axisPointer":{"type":"line","lineStyle":{"width":0}}}],"legend":[{"type":"scroll","data":["\u66dd\u5149\u91cf"],"bottom":0,"selected":[]}],"series":[{"name":"\u66dd\u5149\u91cf","type":"line","yAxisIndex":0,"data":[{"value":895119,"symbol":"emptyCircle"},{"value":972719,"symbol":"emptyCircle"},{"value":937221,"symbol":"emptyCircle"},{"value":906385,"symbol":"emptyCircle"},{"value":814405,"symbol":"emptyCircle"},{"value":810850,"symbol":"circle"},{"value":828829,"symbol":"circle"}],"showAllSymbol":"true"},{"name":"\u4e8b\u9879","type":"pictorialBar","yAxisIndex":0,"data":[{"value":1,"symbol":"emptyCircle","date":"2018-12-03"},{"value":0,"symbol":"emptyCircle"},{"value":0,"symbol":"emptyCircle"},{"value":0,"symbol":"emptyCircle"},{"value":0,"symbol":"emptyCircle"},{"value":0,"symbol":"emptyCircle"},{"value":0,"symbol":"emptyCircle"}],"showAllSymbol":"true"}]}';
$chart = new ECharts();
$chart->setOption(json_decode($data, true));
$resp->end($chart->render('id'));
});
//$http->on('close', function(){
// echo "on close\n";
//});
$http->on('workerStart', function ($serv, $id) {
//var_dump($serv);
});
$http->start();
解决办法,增加一个函数主动重制config静态数组中的数据。或者把config类改成普通类等方式。
在线等,急。谢谢🙏
请问,**市级地区经纬度数据 您这有吗
Hi,
ECHarts from version 5.0 implement of the Dataset option for data transformation. If Dataset option containing Transform object, then Dataset option itself can not be an object, but it must be an array.
Please, how can i use data transformation on the Dataset option?
Example of Dataset option without data transformation:
var option = {
dataset: {
dimensions: {{name: 'product', type: 'ordinal'}, {name: 'count', type: 'number'}},
source: [
['Product', 'Count'],
['Cake', 2],
['Butter', 3]
]
},
...
};
Example Dataset option with data transformation:
var option = {
dataset: [
{
dimensions: {{name: 'product', type: 'ordinal'}, {name: 'count', type: 'number'}},
source: [
['Product', 'Count'],
['Cake', 2],
['Butter', 3]
]
},
{
transform: {
type: 'sort',
config: {
dimension: 'count',
order: 'desc'
}
}
}
],
...
};
You can not create file name with greater-than sign( >) or less than sign (<)
Echarts-PHP/tree/1.0.11/src/Doc/IDE/AngleAxis/AxisLabel/Rich/.php
** 建议一 **
希望有更详细的使用文档和示例,以便我等菜鸡能更好的使用这个超级棒的轮子。
** 建议二 **
PHPStorm 提示 Field Accessed via magic method ,如若能改进甚好(强迫症非必要考虑建议)
使用代码
<?php
// 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');
?>
查过已经安装成功
root@abc:~# composer show hisune/echarts-php
Warning: This development build of composer is over 60 days old. It is recommended to update it by running "/usr/bin/composer self-update" to get the latest version.
Do not run Composer as root/super user! See https://getcomposer.org/root for details
name : hisune/echarts-php
descrip. : A php wrapper for echarts javascript libraries
keywords : charts, echarts, javascript, php
versions : * 1.0.12
type : library
license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
source : [git] https://github.com/hisune/Echarts-PHP.git 8cf5001029839c601ce5d813ab92e6403b647798
dist : [zip] https://api.github.com/repos/hisune/Echarts-PHP/zipball/8cf5001029839c601ce5d813ab92e6403b647798 8cf5001029839c601ce5d813ab92e6403b647798
names : hisune/echarts-php
autoload
psr-4
Hisune\EchartsPHP\ => src/
requires
php >=5.3.0
试过重启php7.3,不过没有作用
Can You prepare examples how to use Your library with examples from Apache ECharts?
option = {
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [{
data: [820, 932, 901, 934, 1290, 1330, 1320],
type: 'line'
}]
};
How to change it to be usefull with Echarts-PHP
Hi there,
I've tried this a few ways, but can't seem to center the title? Any ideas what I'm doing wrong?
$chart1->title->textStyle = ['align'=>'center'];
and
<div class="row"> <div class="col-md-4"> <div> {!! $chart1->render('simple-custom-id') !!} </div> </div> <div class="col-md-8"> {!! $chart2->render('simple-custom-id2') !!} </div> </div>
What might I be missing?
Thanks!
请问,安装这个lib后,如何实现动态图呢?
composer 安装echarts。
$chart = new ECharts();
$chart->tooltip->show = true;
$chart->legend->data[] =['销量',‘金额’];// 想添加多个参数,不知道这个地方怎么写,写数组还是什么? 方便给个案例吗?
$chart->xAxis[] = array(
'type' => 'category',
'data' => $name
);
$chart->yAxis[] = array(
'type' => 'value'
);
$chart->series[] = array(//这块的数据是根据legend参数个数填写吗?
[
'name' => '销量',
'type' => 'line',
'data' => $value,
],
[
'name' => '金额',
'type' => 'line',
'data' => $money,
],
);
根据我上面错误的代码能明白我想要的效果吗? 就是不知道legend 和series多个参数时要怎么写...
参考这里。
对于联网的网站,可以采用上述网址里的做法。下面叙述对无法联网的或者想把echarts下载后放在自己网站离线使用的做法。
百度的echarts为JavaScript/CSS包,采用Bower管理。可以采用如下方式在YII2中使用。
假设你的网站目录为_./basic_。
#1. 下载echarts。
下载百度的echarts-2.2.7.zip压缩包,解压缩后放在
_./basic/vendor/bower/echarts-2.2.7/_下。
#2. 重命名echarts(非必须)。
查看目录_./basic/vendor/bower/echarts-2.2.7/下面应该有_build,src,doc_等文件夹以及_bower.json,LICENSE.txt_等文件。为方便使用,把文件夹_echarts-2.2.7_改为_echarts。
#3. 修改_composer.json_文件。
vi ./basic/composer.json
找到**_require**_这一项,应该有类似如下的内容。
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": "2.0.6",
"yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-swiftmailer": "*",
"phpoffice/phpexcel": "^1.8"
},
在最后一行加入**"bower-asset/echarts": ">=2.2.1"**,
变成如下形式。
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": "2.0.6",
"yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-swiftmailer": "*",
"phpoffice/phpexcel": "^1.8",
"bower-asset/echarts": ">=2.2.7"
},
#4. 创建asset bundle类。
在目录_./basic/assets/_创建EchartsAsset.php文件。内容如下。
/**
* Write Asset for Echarts.
*/
namespace app\assets;
use yii\web\AssetBundle;
class EchartsAsset extends AssetBundle
{
public $sourcePath = '@bower/echarts/build/dist';
public $js = [
'echarts.js',
];
}
内容参照AssetBundle的教程做的。通过查阅echarts的教程,发现一般他们调用的都是_./echarts/build/dist/的内容,所以文中设置$sourcePath_指向该文件夹。
其中_@bower_,YII2会自动找到_./basic/vendor/bower/_文件夹的。
$js_是查找./echarts/build/dist/_下的_js_文件,列出来的。
这样完成了AssetBundle的配置。
#5. 安装Echarts-PHP插件。
在目录_./basic/_下输入命令
composer require "hisune/echarts-php"
或者类似的命令或者直接在github下载,
解压缩放在目录_./basic/vendor/_下。
#6. 输出echarts图像。
下面举个简单的例子。
打开_site/index.php_文件。
vi ./basic/views/site/index.php
加入如下内容
<?php
use app\assets\EchartsAsset;
use Hisune\EchartsPHP\ECharts;
$asset=EchartsAsset::register($this);
$chart = new ECharts($asset->baseUrl);
$chart->tooltip->show = true;
$chart->legend->data = array('销量');
$chart->xAxis = array(
array(
'type' => 'category',
'data' => array("衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子")
)
);
$chart->yAxis = array(
array('type' => 'value')
);
$chart->series = array(
array(
'name' => '销量',
'type' => 'bar',
'data' => array(5, 20, 40, 10, 10, 20)
)
);
echo $chart->render('simple-custom-id');
解说:
第一第二行代码是加入我们需要的类EchartsAsset跟EchartsPHP。
第三行空,第四行第五行注册EchartsAsset类,并把注册后的_baseUrl_传递给EchartsPHP类,供查找_JavaScript/CSS_文件的位置。
第六行及以后赋值,这个可以参考百度的Echarts实例跟EchartsPHP的配置。自己找规律。
最后一行,输出图像。
$chart->toolbox->show=true;
但是渲染的页面未显示帮助工具
你好,我的网站无法访问外网。在yii2,php下开发。我也看到你的配置里有
public static $dist = 'https://cdnjs.cloudflare.com/ajax/libs/echarts/2.2.5';
我想把他替换为本地已经下载好的echarts,可有好的办法吗?
或者可以把这个方法写在readme.md里。
谢谢。
Hey guys, is this project still alive? There is at least one php8.1 deprecation notice.
E_DEPRECATED: Return type of Hisune\EchartsPHP\Property::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
It is present in latest version 1.1.2 from packagist. Maybe it is already fixed in dev-master and you may create a new tag.
Hi, is it possible to generate chart into image? Thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.