public function Highcharts::preRender in Charts 5.0.x
Same name and namespace in other branches
- 8.4 modules/charts_highcharts/src/Plugin/chart/Library/Highcharts.php \Drupal\charts_highcharts\Plugin\chart\Library\Highcharts::preRender()
Pre render.
Parameters
array $element: The element.
Return value
array The chart element.
Overrides ChartInterface::preRender
File
- modules/
charts_highcharts/ src/ Plugin/ chart/ Library/ Highcharts.php, line 163
Class
- Highcharts
- Defines a concrete class for a Highcharts.
Namespace
Drupal\charts_highcharts\Plugin\chart\LibraryCode
public function preRender(array $element) {
// Populate chart settings.
$chart_definition = [];
$chart_definition = $this
->populateOptions($element, $chart_definition);
$chart_definition = $this
->populateAxes($element, $chart_definition);
$chart_definition = $this
->populateData($element, $chart_definition);
// Remove machine names from series. Highcharts series must be an array.
$series = array_values($chart_definition['series']);
unset($chart_definition['series']);
// Trim out empty options (excluding "series" for efficiency).
ChartElement::trimArray($chart_definition);
// Put back the data.
$chart_definition['series'] = $series;
if (!isset($element['#id'])) {
$element['#id'] = Html::getUniqueId('highchart-render');
}
$element['#attached']['library'][] = 'charts_highcharts/highcharts';
if ($this->configuration['exporting_library'] == TRUE) {
$element['#attached']['library'][] = 'charts_highcharts/highcharts_exporting';
}
$element['#attributes']['class'][] = 'charts-highchart';
$element['#chart_definition'] = $chart_definition;
return $element;
}