Пример #1
0
 /**
  * Creates and returns the JSON encoded chart details, options and data
  * from the injected Chart, generally called by the view layer
  * @param  Chart  $chart Instance of Phighchart\Chart
  * @return String $ret  The JSON string to display the complete chart
  */
 public function render(Chart $chart)
 {
     if ($chart->getData()->getCounts()) {
         // prepare the data
         $series = array();
         foreach ($chart->getData()->getCounts() as $key => $count) {
             // prepare the series item
             $seriesItem = new \StdClass();
             $seriesItem->name = $key;
             $seriesItem->y = $count;
             // add the sticky colour if present
             if ($colour = $this->_getStickyColour($chart, $key)) {
                 $seriesItem->color = $colour;
             }
             // add to the series
             $series[] = $seriesItem;
         }
         // make it a pie chart and pass back in the prepared data
         $chartSeriesOptions = $chart->getOptionsType('series', new Container('series'));
         $chartSeriesOptions->setType('pie');
         $chartSeriesOptions->setData($series);
         // get all the existing options
         $options = $chart->getOptionsForOutput();
         // add the series as a nested array
         $options['series'] = array($chartSeriesOptions->getOptions());
         // send back the prepared chart JS
         return $this->outputJavaScript($chart, $options);
     }
     return '';
 }
Пример #2
0
 /**
  * Creates and returns the JSON encoded chart details, options and data
  * from the injected Chart, generally called by the view layer
  * @param  Chart  $chart Instance of Phighchart\Chart
  * @return String $ret  The JSON string to display the complete chart
  */
 public function render(Chart $chart)
 {
     // make it a line chart
     $chartOptions = $chart->getOptionsType('chart', new Container('chart'));
     $chartOptions->setType('column');
     $chart->addOptions($chartOptions);
     // prepare the data
     $series = array();
     //formatter for rendering this chart
     $format = $chart->getFormat();
     // for each series of data (a series is a line)
     foreach ($chart->getData()->getSeries() as $key => $seriesData) {
         // add each one to the chart along with a sticky colour if present
         $seriesItem = new \StdClass();
         $seriesItem->name = $key;
         $seriesItem->data = $format->getFormattedChartData($seriesData);
         if ($colour = $this->_getStickyColour($chart, $key)) {
             $seriesItem->color = $colour;
         }
         $series[] = $seriesItem;
     }
     if ($formatOptions = $format->getFormatOptions($chart)) {
         $chart->addOptions($formatOptions);
     }
     // get all the existing options
     $options = $chart->getOptionsForOutput();
     // add the series data
     $options['series'] = $series;
     // send back the prepared chart JS
     return $this->outputJavaScript($chart, $options);
 }
Пример #3
0
 public function render(Chart $chart)
 {
     //set the chart type to area
     $chartSection = $chart->getOptionsType('chart', new Container('chart'));
     $chartSection->setType('area');
     $chart->addOptions($chartSection);
     //prepare series array
     $series = array();
     //formatter for rendering this chart
     $format = $chart->getFormat();
     foreach ($chart->getData()->getSeries() as $key => $seriesData) {
         $member = new \StdClass();
         $member->name = $key;
         $member->data = $format->getFormattedChartData($seriesData);
         //check if a sticky colour is defined for the key of this member
         if ($colour = $this->_getStickyColour($chart, $key)) {
             $member->color = $colour;
         }
         //commit member to the series
         $series[] = $member;
     }
     if ($formatOptions = $format->getFormatOptions($chart)) {
         $chart->addOptions($formatOptions);
     }
     //return the series data
     $options = $chart->getOptionsForOutput();
     $options['series'] = $series;
     return $this->outputJavaScript($chart, $options);
 }
Пример #4
0
 public function testGetData()
 {
     $chart = new Chart();
     $data = new Data();
     $chart->setData($data);
     $this->assertInstanceOf('Phighchart\\Data', $chart->getData());
 }