Beispiel #1
0
 public function testChangeJsIncludedAfterWhenRendering()
 {
     $manager = Manager::getInstance();
     $manager->setJsIncluded(true);
     $chart = $this->getMockForAbstractClass('AmCharts\\Chart\\AbstractChart');
     $this->renderer->setChart($chart);
     $output = $this->renderer->renderHtml();
     $this->assertRegExp('/<script(.*?)>(.*?)<\\/script>/', $output);
     $this->assertFalse($manager->hasIncludedJs());
 }
Beispiel #2
0
 /**
  * @return string
  */
 public function renderHtml()
 {
     $html = '';
     $manager = Manager::getInstance();
     if ($manager->hasIncludedJs()) {
         $html .= $this->renderScriptTag(null, array('src' => $manager->getAmChartsPath())) . "\n";
         if ($manager->isLoadingJQuery()) {
             $html .= $this->renderScriptTag(null, array('src' => $manager->getJQueryPath())) . "\n";
         }
         $manager->setJsIncluded(false);
     }
     $html .= sprintf('<div id="%s" style="width:%s;height:%s;"></div>', $this->chart->getId(), $this->chart->getWidth(), $this->chart->getHeight());
     return $html;
 }
 /**
  * Returns params
  *
  * @return array
  */
 public function getParams()
 {
     $params = array();
     $manager = Manager::getInstance();
     $imagesPath = $manager->getImagesPath();
     if ($imagesPath) {
         $params['pathToImages'] = $imagesPath;
     }
     $dataProvider = $this->getDataProvider();
     if (null !== $dataProvider) {
         $data = $dataProvider->toArray();
         $params['dataProvider'] = json_encode(array_values($data));
     }
     return $params;
 }
 public function testRender()
 {
     Manager::getInstance()->setLoadJQuery(true);
     $output = $this->chart->render();
     $this->assertNotEquals(false, strpos($output, 'script'));
 }
Beispiel #5
0
<?php

/**
 * AmChartsPHP
 * 
 * @link      http://github.com/neeckeloo/AmChartsPHP
 * @copyright Copyright (c) 2012 Nicolas Eeckeloo
 */
require_once dirname(dirname(__DIR__)) . '/vendor/autoload.php';
use AmCharts\Chart, AmCharts\Graph, AmCharts\Manager as ChartManager;
$manager = ChartManager::getInstance();
$manager->setAmChartsPath('./amcharts.js');
$serial = new Chart\Serial();
$dataProvider = Chart\DataProvider\Factory::fromFile(__DIR__ . '/data.xml');
$serial->setDataProvider($dataProvider);
$serial->setCategoryField('country')->setStartDuration(1);
$serial->categoryAxis()->setGridPosition('start')->setLabelRotation(45)->setGridAlpha(0)->setFillAlpha(100)->setFillColor('#FAFAFA');
$serial->valueAxis()->setDashLength(5)->setAxisAlpha(0)->title()->setValue('Visitors from country');
$graph = new Graph\Column();
$graph->fields()->setValueField('visits')->setColorField('color');
$graph->setFillAlphas(100)->setLineAlpha(0)->setBalloonText('[[category]]: [[value]]');
$serial->addGraph($graph);
echo $serial->render();