コード例 #1
0
 /**
  * @return GoogleGridedLineChart
  **/
 private function createDefault()
 {
     $this->grid = GoogleChartGrid::create();
     $maxSteps = $this->getData()->getMaxSteps();
     if ($maxSteps > 0) {
         $this->grid->setVerticalStepSize(round(100 / $maxSteps, 1));
     }
     if (($axis = $this->axesCollection->getAxisByTypeId(GoogleChartAxisType::X)) && ($label = $axis->getLabel()) && $label->getCount() > 1) {
         $this->grid->setHorizontalStepSize(round(100 / ($label->getCount() - 1), 2));
     }
     return $this;
 }
コード例 #2
0
 public function testGridedLineChart()
 {
     $views = GoogleChartDataSet::create()->setData(array(0, 0, 20, 2491, 2334, 0));
     $clicks = GoogleChartDataSet::create()->setData(array(0, 0, 10, 480, 530, 0));
     $days = array(2.03, 9.029999999999999, 16.03, 23.03, 30.03, 6.04);
     // calc base (thanks Igor V. Gulyaev)
     $views->setBase(pow(10, floor(log10($views->getMax()))));
     $clicks->setBase(pow(10, floor(log10($clicks->getMax()))));
     $viewAxis = GoogleChartAxis::create(new GoogleChartAxisType(GoogleChartAxisType::Y))->setRange($views->getMinMax())->setInterval($views->getBase());
     $clickAxis = GoogleChartAxis::create(new GoogleChartAxisType(GoogleChartAxisType::R))->setRange($clicks->getMinMax())->setInterval($clicks->getBase());
     $chart = GoogleGridedLineChart::create()->setSize(GoogleChartSize::create()->setWidth(640)->setHeight(240))->addAxis($viewAxis)->addAxis($clickAxis)->addAxis(GoogleChartAxis::create(new GoogleChartAxisType(GoogleChartAxisType::X))->setLabel(GoogleChartAxisLabel::create()->setLabels($days)))->addLine(GoogleChartLine::create()->setTitle('Показы')->setColor(Color::create('6699cc'))->setValue($views)->setStyle(ChartLineStyle::create()->setThickness(2)))->addLine(GoogleChartLine::create()->setTitle('Клики')->setColor(Color::create('339922'))->setValue($clicks)->setStyle(ChartLineStyle::create()->setThickness(2)));
     $this->assertEquals($chart->toString(), 'http://chart.apis.google.com/chart?cht=lc&chs=640x240&chco=6699CC,339922&chd=t:0,0,20,2491,2334,0|0,0,10,480,530,0&chds=0,6000,0,600&chdl=Показы|Клики&chdlp=b&chxt=y,r,x&chxr=0,0,6000,1000|1,0,600,100&chxl=2:|2.03|9.03|16.03|23.03|30.03|6.04&chls=2,1,0|2,1,0&chg=20,16.7,0');
     $chart->setGrid(GoogleChartGrid::create()->setVerticalStepSize(10));
     $this->assertEquals($chart->toString(), 'http://chart.apis.google.com/chart?cht=lc&chs=640x240&chco=6699CC,339922&chd=t:0,0,20,2491,2334,0|0,0,10,480,530,0&chds=0,6000,0,600&chdl=Показы|Клики&chdlp=b&chxt=y,r,x&chxr=0,0,6000,1000|1,0,600,100&chxl=2:|2.03|9.03|16.03|23.03|30.03|6.04&chls=2,1,0|2,1,0&chg=0,10,0');
 }