public function testLineChartCreation() { $chart = new GridChart(); $chart->drawLines(array('label' => 'My bar', 'color' => 'black', 'data' => array(array(0, 0), array(1, 1), array(1, 2)))); $doc = new DOMDocument(); $doc->preserveWhiteSpace = false; $doc->loadXML($chart->render()); $xpath = new DOMXPath($doc); $xpath->registerNamespace('x', 'http://www.w3.org/2000/svg'); $path = $xpath->query('//x:path[@data-icinga-graph-type="line"]'); $this->assertEquals(1, $path->length, 'Assert the correct number of datapoints being drawn as SVG lines'); }
private function drawLogChart3() { $chart = new GridChart(); $chart->alignTopLeft(); $chart->setAxisLabel('X axis label', 'Y axis label')->setYAxis(new LogarithmicUnit()); for ($i = -2; $i < 3; $i++) { $sign = $i > 0 ? 1 : ($i < 0 ? -1 : 0); $data[] = array($i, $sign * pow(10, abs($i))); } $chart->drawLines(array('label' => 'f(x): sign(x) * 10^|x|', 'color' => '#F56', 'data' => $data, 'showPoints' => true)); return $chart; }
/** * Notifications and defects * * @return GridChart */ public function createDefectImage() { $gridChart = new GridChart(); $gridChart->title = $this->translate('Defect Chart'); $gridChart->description = $this->translate('Notifications and defects per hour'); $gridChart->alignTopLeft(); $gridChart->setAxisLabel($this->createPeriodDescription(), $this->translate('Notifications'))->setXAxis(new StaticAxis())->setYAxis(new LinearUnit(10))->setAxisMin(null, 0); $gridChart->drawBars(array('label' => $this->translate('Notifications'), 'color' => '#07C0D9', 'data' => $this->notificationData, 'showPoints' => true, 'tooltip' => '<b>{title}:</b> {value} {label}')); $gridChart->drawLines(array('label' => $this->translate('Defects'), 'color' => '#ff5566', 'data' => $this->problemData, 'showPoints' => true, 'tooltip' => '<b>{title}:</b> {value} {label}')); return $gridChart; }