More code for issue #452

This commit is contained in:
James Cole
2016-12-11 16:25:25 +01:00
parent 77560ab3a8
commit 0f260da8e6
3 changed files with 57 additions and 24 deletions

View File

@@ -61,4 +61,31 @@ class ChartJsGenerator implements GeneratorInterface
return $chartData;
}
/**
* Will generate a (ChartJS) compatible array from the given input. Expects this format:
*
* 'label-of-entry' => value
* 'label-of-entry' => value
*
* @param string $setLabel
* @param array $data
*
* @return array
*/
public function singleSet(string $setLabel, array $data): array
{
$chartData = [
'count' => 1,
'labels' => array_keys($data), // take ALL labels from the first set.
'datasets' => [
[
'label' => $setLabel,
'data' => array_values($data),
],
],
];
return $chartData;
}
}