It includes a set of built-in formatters to handle common preprocessing tasks (like converting
datetime strings to JavaScript timestamps) and provides an extensible column configuration, which
allows you to add custom parser/formatter handlers.
Basic usage:
php
use miloschuman\highcharts\Highstock;
use miloschuman\highcharts\SeriesDataHelper;
Highstock::widget([
'options' => [
'series' => [
[
'type' => 'candlestick',
'name' => 'Stock',
'data' => new SeriesDataHelper($dataProvider, ['date:datetime', 'open', 'high', 'low', 'close']),
],
[
'type' => 'column',
'name' => 'Volume',
'data' => new SeriesDataHelper($dataProvider, ['date:datetime', 'volume:int']),
],
]
]
]);
/** * test fancy data processing to produce JS objects instead of arrays */ public function testFancyDataProcessing() { $data = [['date_measured' => '2016-03-01 03:00:00', 'open' => 3.14, 'pointData' => 'Show this on the graph'], ['date_measured' => '2016-03-02 03:00:00', 'open' => 4.14, 'pointData' => 'This as well']]; $columns = ['x' => ['date_measured', 'datetime'], 'y' => 'open:int', 'extra' => 'pointData:raw']; $dataProvider = $this->setupDataProvider($data); $helper = new SeriesDataHelper($dataProvider, $columns); $results = $helper->jsonSerialize(); $this->assertEquals(strtotime('2016-03-01 03:00:00') * 1000, $results[0]['x']); $this->assertEquals(3, $results[0]['y']); $this->assertEquals('Show this on the graph', $results[0]['extra']); $this->assertEquals(strtotime('2016-03-02 03:00:00') * 1000, $results[1]['x']); $this->assertEquals(4, $results[1]['y']); $this->assertEquals('This as well', $results[1]['extra']); }