/** * Generates JSON graph data and returns it. * * @param DataTable|DataTable\Map $dataTable * @return string */ public function generate($dataTable) { $visualization = new Chart(); if ($dataTable->getRowsCount() > 0) { // if addTotalRow was called in GenerateGraphHTML, add a row containing totals of // different metrics if ($this->properties['add_total_row']) { $dataTable->queueFilter('AddSummaryRow', Piwik::translate('General_Total')); } $dataTable->applyQueuedFilters(); $this->initChartObjectData($dataTable, $visualization); } return $visualization->render(); }
/** * @param DataTable\Map $dataTableMap * @param string $columnToPlot * * @return array * @throws \Exception */ protected function getValuesFromDataTableMap($dataTableMap, $columnToPlot) { $dataTableMap->applyQueuedFilters(); $values = array(); foreach ($dataTableMap->getDataTables() as $table) { if ($table->getRowsCount() > 1) { throw new Exception("Expecting only one row per DataTable"); } $value = 0; $onlyRow = $table->getFirstRow(); if (false !== $onlyRow) { if (!empty($columnToPlot)) { $value = $onlyRow->getColumn($columnToPlot); } else { $columns = $onlyRow->getColumns(); $value = current($columns); } } $values[] = $value; } return $values; }