/** * @return GoogleLineChart **/ public function addLine(GoogleChartLine $line) { $this->color->addColor($line->getColor()); $this->legend->addItem($line->getTitle()); $this->data->addDataSet($line->getValue()); if ($style = $line->getStyle()) { $this->style->addStyle($style); } if ($labelStyle = $line->getLabelStyle()) { $this->labelStyle->addStyle($labelStyle->setDataSetIndex($this->data->getCount() - 1)); } return $this; }
/** * @dataProvider twoAxisDataProvider **/ public function testTwoAxis($firstAxisData, $secondtAxisData, $result) { foreach ($result as $chartClass => $expectedString) { $views = GoogleChartDataSet::create()->setData($firstAxisData); $clicks = GoogleChartDataSet::create()->setData($secondtAxisData); $chart = new $chartClass(); if ($chart->getData()->isNormalized()) { if ($views->getMax() >= 10) { $base = pow(10, floor(log10($views->getMax()))); } else { $base = 0.1; } $views->setBase($base); if ($clicks->getMax() >= 10) { $base = pow(10, floor(log10($clicks->getMax()))); } else { $base = 0.1; } $clicks->setBase($base); } $viewAxis = GoogleChartAxis::create(new GoogleChartAxisType(GoogleChartAxisType::Y))->setRange($views->getMinMax()); $clickAxis = GoogleChartAxis::create(new GoogleChartAxisType(GoogleChartAxisType::R))->setRange($clicks->getMinMax()); if ($chart->getData()->isNormalized()) { $viewAxis->setInterval($views->getBase()); $clickAxis->setInterval($clicks->getBase()); } $chart->setSize(GoogleChartSize::create()->setWidth(300)->setHeight(300))->addAxis($viewAxis)->addLine(GoogleChartLine::create()->setTitle('Показы')->setColor(Color::create('336699'))->setValue($views))->addAxis($clickAxis)->addLine(GoogleChartLine::create()->setTitle('Клики')->setColor(Color::create('339911'))->setValue($clicks)); $this->assertEquals($expectedString, $chart->toString()); } }