Пример #1
0
 public function testAddMultipleOptionsContainers()
 {
     $chart = new Chart();
     $options = new Container('test');
     $options->setFoo('bar');
     $options2 = new Container('test2');
     $options2->setFoo('bar1');
     $options2->setFoo2('bar2');
     $chart->addOptions(array($options, $options2));
     $this->assertInstanceOf('Phighchart\\Options\\Container', $chart->getOptionsType('test'));
     $this->assertInstanceOf('Phighchart\\Options\\Container', $chart->getOptionsType('test2'));
     $this->assertSame($chart->getOptionsType('test')->getOption('foo'), 'bar');
     $this->assertSame($chart->getOptionsType('test2')->getOption('foo'), 'bar1');
     $this->assertSame($chart->getOptionsType('test2')->getOption('foo2'), 'bar2');
 }
Пример #2
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);
 }
Пример #3
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);
 }
Пример #4
0
 /**
  * Retrieves the renderTo option from the 'chart' options
  * @return String     $renderTo The renderTo option from the 'chart' options
  * @throws \Exception chart options or renderTo is not set
  */
 public function getRenderTo(Chart $chart)
 {
     // fetch the renderTo option
     if (!($options = $chart->getOptionsType('chart')) || !($renderTo = $options->getOption('renderTo'))) {
         throw new \Exception("Render To option within chart options must be defined (renderTo)", 1);
     }
     return $renderTo;
 }
Пример #5
0
 /**
  * Sets the xAxis type as datetime and returns it in a Phighchart\Container
  * @param  Chart                $chart chart instance
  * @return Phighchart\Container
  */
 public function getFormatOptions(Chart $chart)
 {
     $xAxis = $chart->getOptionsType('xAxis', new Container('xAxis'));
     $xAxis->setType('datetime');
     return $xAxis;
 }