catchamonkey / phighcharts
用于Highcharts JavaScript图表库的PHP库
v0.1.3
2013-05-07 15:59 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-14 14:14:16 UTC
README
#Phighcharts
一个PHP库(需要PHP 5.3),用于Highcharts JavaScript图表库
##安装
composer require "catchamonkey/phighcharts"
##它做什么?除了提供创建图表的OO接口外,它还通过添加如“粘性键”等有用的工具来扩展功能
###粘性键 粘性键是一个配置选项,允许您始终使用相同的颜色为某些键。例如,当图表苹果与橙子时,您可能希望始终使用绿色表示苹果。
##示例饼图
<?php use Phighchart\Chart; use Phighchart\Options\Container; use Phighchart\Options\ExtendedContainer; use Phighchart\Data; use Phighchart\Renderer\Pie; use Phighchart\Renderer\Line; $extOptions = new ExtendedContainer(); $extOptions->setStickyColour('apples', '#629632'); $extOptions->setStickyColour('oranges', '#CD3700'); $options = new Container('chart'); $options->setRenderTo('chart_example_59'); $options->setMarginRight(130); $options->setMarginBottom(25); $titleOptions = new Container('title'); $titleOptions->setText('Monthly Details'); $titleOptions->setX(-20); $data = new Data(); $data ->addCount('Apples', 32) ->addCount('Oranges', 68) ->addSeries('Apples', array( '2012-05-01' => 12, '2012-05-02' => 3, '2012-05-03' => 33 )) ->addSeries('Oranges', array( '2012-05-01' => 32, '2012-05-02' => 36, '2012-05-03' => 18 )); // put it all together $chart = new Chart(); $chart ->addOptions($options) ->addOptions($titleOptions) ->addOptions($extOptions) ->setData($data) ->setRenderer(new Pie()); // a line chart is similar, and our data container holds series data for this $lineChart = clone $chart; $options = new Container('chart'); $options->setRenderTo('chart_example_60'); $options->setMarginRight(130); $options->setMarginBottom(25); $lineChart->addOptions($options)->setRenderer(new Line()); // and render in the template $chart->renderContainer(); // or to change the element rendered // $chart->renderContainer('span'); $chart->render(); // and for the line $lineChart->renderContainer(); $lineChart->render(); ?>
要按datetime格式渲染标签,提供格式类的实例。注意:Phighchart默认使用线性格式
<?php use Phighchart\Format\Datetime; //set up chart and chart data $dateTimeFormat = new Datetime(); $chart->setFormat($dateTimeFormat); ?>
DateTime格式化器现在将尝试将图表数据键解析为DateTime对象。DateTime格式化类可以开箱即用地解析标准的PHP日期时间字符串格式。
参考
- http://no2.php.net/manual/en/datetime.formats.compound.php
- http://no2.php.net/manual/en/datetime.formats.date.php
对于解析自定义日期时间字符串格式,将日期时间字符串模式提供给Phighchart DateTime格式化类,如下所示
<?php use Phighchart\Format\Datetime; //set up chart and chart data $dateTimeFormat = new Datetime(); //for parsing date time string of pattern "1st August, 2012 12:09:32" $dateTimeFormat->setDateTimeFormat('jS F, Y H:i:s'); $chart->setFormat($dateTimeFormat); ?>
##单元测试
您可以使用以下命令运行单元测试套件;
phpunit -c . tests/