public function ChartTrait::renderChart in Dashboards with Layout Builder 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/Dashboard/ChartTrait.php \Drupal\dashboards\Plugin\Dashboard\ChartTrait::renderChart()
Set all rows.
Parameters
array $conf: Plugin configuration.
bool $plain: Show only table.
Return value
array Return renderable array.
4 calls to ChartTrait::renderChart()
- Comments::buildRenderArray in modules/
dashboards_comments/ src/ Plugin/ Dashboard/ Comments.php - Build render array.
- MostReaded::buildRenderArray in modules/
dashboards_statistic/ src/ Plugin/ Dashboard/ MostReaded.php - Build render array.
- NodeStatistics::buildRenderArray in src/
Plugin/ Dashboard/ NodeStatistics.php - Build render array.
- Submissions::buildRenderArray in modules/
dashboards_webform/ src/ Plugin/ Dashboard/ Submissions.php - Build render array.
File
- src/
Plugin/ Dashboard/ ChartTrait.php, line 133
Class
- ChartTrait
- Trait for build a chart.
Namespace
Drupal\dashboards\Plugin\DashboardCode
public function renderChart(array $conf = [], bool $plain = FALSE) : array {
if (count($this->rows) == 0) {
return [
'#markup' => $this
->t('No data found'),
];
}
$table = [
'#type' => 'table',
'#header' => $this->labels,
'#rows' => $this->rows,
'#attributes' => [
'class' => [
'dashboard-table',
'table',
],
],
'#attached' => [
'library' => [
'dashboards/chart',
],
],
];
$attributes = [
'data-app' => 'chart',
'data-chart-type' => $this->type,
];
if (isset($conf['legend']) && $conf['legend']) {
$attributes['data-chart-display-legend'] = '1';
}
$build = [
'#prefix' => '<div>',
'#suffix' => '</div>',
'chart' => [
'#type' => 'container',
'#attributes' => $attributes,
[
'#type' => 'container',
[
'#type' => 'details',
'#title' => $this
->t('Show data'),
'#open' => FALSE,
'content' => $table,
],
],
],
];
if ($plain == TRUE) {
unset($build['#attributes']);
unset($build['chart']['table']['#attached']);
}
return $build;
}