koenster / php-graphs
一个用于JS图表的PHP库。
v0.1.2
2016-06-12 14:35 UTC
Requires
- php: >=5.5.9
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-09-28 18:58:40 UTC
README
#PHP 图表
一个PHP库,可以将数据集合转换为图形对象,然后您最喜欢的JS图表库可以将它转换为应用程序中美丽的图表。
##要求
- PHP 5.5.9 或更高版本
##支持的JavaScript库
当前JS实现
- Chart.js (https://chart.js.cn/)
- morris.js (http://morrisjs.github.io/morris.js/)
##实现
###应用程序
use koenster\PHPGraphs\contract\ChartContract;
use koenster\PHPGraphs\PHPChart;
$chart = new PHPChart(PHPChart::IMPLEMENTATION_CHART_JS);
$graph = $chart->add(PHPChart::TYPE_LINE, 'results', ['width' => 400, 'height' => 400]);
$graph->setLine([100,75,50,75,50,75,100], ['label' => 'Costs'])
->setLine([90,65,40,65,40,65,150], ['label' => 'Revenue'])
->setDimensions(['2006', '2007', '2008', '2009', '2010', '2011', '2012']);
###视图
<!doctype html>
<html>
<head>
<!-- This is optional -->
<?php foreach ($chart->getFactory()->getCss() as $css) : ?>
<link rel="stylesheet" href="{{ $css }}">
<?php endforeach; ?>
<!-- This is optional -->
<?php foreach ($chart->getFactory()->getJs() as $js) : ?>
<script src="<?php echo $js; ?>"></script>
<?php endforeach; ?>
</head>
<body>
<!-- This will generate the HTML code -->
<?php echo $graph->generate(); ?>
<script>
// This will gather all charts and activate the JS library to convert the provided JSON to a Graph
<?php echo $chart->getFactory()->getJsPartial(); ?>
</script>
对于完整实现(折线图、面积图、饼图等),请参阅示例目录。
##贡献
##待办事项(随机顺序)
- 更详细的wiki/文档
- 更多实现
- 每个实现更多的配置(添加更多配置变量)
- 更好的验证
##未来的实现
- Chrtist.js -> https://gionkunz.github.io/chartist-js/
- jQuery flot -> http://www.flotcharts.org/
##许可
此PHP Graph库是开源软件,采用MIT许可。