private function Chartjs::populateOptions in Charts 8.4
Same name and namespace in other branches
- 5.0.x modules/charts_chartjs/src/Plugin/chart/Library/Chartjs.php \Drupal\charts_chartjs\Plugin\chart\Library\Chartjs::populateOptions()
Populate options.
Parameters
array $element: The element.
array $chart_definition: The chart definition.
Return value
array Return the chart definition.
1 call to Chartjs::populateOptions()
- Chartjs::preRender in modules/
charts_chartjs/ src/ Plugin/ chart/ Library/ Chartjs.php - Pre render.
File
- modules/
charts_chartjs/ src/ Plugin/ chart/ Library/ Chartjs.php, line 194
Class
- Chartjs
- Define a concrete class for a Chart.
Namespace
Drupal\charts_chartjs\Plugin\chart\LibraryCode
private function populateOptions(array $element, array $chart_definition) {
$chart_type = $this
->populateChartType($element);
$chart_definition['type'] = $chart_type;
if (!in_array($chart_type, [
'pie',
'doughnut',
])) {
if (!empty($element['#stacking']) && $element['#stacking'] == 1) {
$stacking = TRUE;
}
else {
$stacking = FALSE;
}
$chart_definition['options']['scales']['xAxes'][] = [
'stacked' => $stacking,
];
$chart_definition['options']['scales']['yAxes'][] = [
'ticks' => [
'beginAtZero' => NULL,
],
'maxTicksLimit' => 11,
'precision' => NULL,
'stepSize' => NULL,
'suggestedMax' => NULL,
'suggestedMin' => NULL,
'stacked' => $stacking,
];
}
$chart_definition['tooltips'] = [
'enabled' => TRUE,
];
$chart_definition['legend'] = [
'display' => TRUE,
'position' => 'right',
];
$chart_definition['title'] = [
'display' => TRUE,
'position' => 'out',
'text' => 'Weekly project usage',
];
$chart_definition['scaleColorRanges'] = NULL;
$chart_definition['range'] = NULL;
// Merge in chart raw options.
if (!empty($element['#raw_options'])) {
$chart_definition = NestedArray::mergeDeepArray([
$element['#raw_options'],
$chart_definition,
]);
}
return $chart_definition;
}