Echarts-PHP is a PHP library that works as a wrapper for the Echarts js library (https://github.com/ecomfe/echarts). Support echarts version from 2.2.x to 3.x.
// 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');
use \Hisune\EchartsPHP\Config;
use \Hisune\EchartsPHP\Doc\IDE\Series;
$chart = new ECharts();
$chart->visualMap->min = 0;
$chart->visualMap->max = 100;
$chart->visualMap->text = ['High', 'Low'];
$chart->visualMap->calculable = true;
$chart->visualMap->inRange->color = ['#C843C8', '#441744'];
$chart->tooltip->trigger = 'item';
$chart->tooltip->formatter = '{a}
{b} {c}';
$series = new Series();
$series->name = 'Times';
$series->type = 'map';
$series->map = 'world';
// echart默认是用不规范的英文国家名做映射关系,这里转为标准的ISO3166-1国家短码
$series->nameMap = \Hisune\EchartsPHP\Countries::nameMap();
// 在data中使用ISO3166-1国家短码
$series->data = [
[
'name' => 'CN',
'value' => 100,
],
[
'name' => 'US',
'value' => 50,
],
[
'name' => 'RU',
'value' => 80,
],
[
'name' => 'IN',
'value' => 20,
],
[
'name' => 'CA',
'value' => 80,
],
[
'name' => 'AU',
'value' => 30,
]
];
$series->label->emphasis->show = false;
$series->label->emphasis->textStyle->color = '#fff';
$series->roam = true;
$series->scaleLimit->min = 1;
$series->scaleLimit->max = 5;
$series->itemStyle->normal->borderColor = '#bbb';
$series->itemStyle->normal->areaColor = '#F5F6FA';
$series->itemStyle->emphasis->areaColor = '#441744';
$chart->addSeries($series);
Config::addExtraScript('world.js', 'https://cdn.rawgit.com/hisune/images/7b31b0a0/echarts');
echo $chart->render('map', ['style' => 'height: 500px;']);