Пример #1
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);
 }
Пример #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);
 }