I’m programming a block in Drupal 8:
class B extends BlockBase implements BlockPluginInterface { public function build() { return []; // cannot figure out what to return here } }
I read that in D8 a block’s build
function should return a render-array, like this:
return ['#markup' => 'Some HTML'];
Then in the Charts source code I found some examples here and there, especially in PHPDOC comments, so I built a render-array like this:
$ return = [ $ chart = [ '#type' => 'chart', '#chart_type' => 'line', '#chart_library' => 'c3', 'xaxis' => [ '#type' => 'chart_xaxis', '#title' => 'XTitle', '#labels' => range(1, 10), ], 'yaxis' => [ '#type' => 'chart_yaxis', '#title' => 'YTitle' ], 'series_1' => ['#type' => 'chart_data', '#title' => $ seriesTitle, '#data' => range(1, 10) ], // more series here keyed series_2, series_3 etc ] ];
Nothing is output (only block title). No JS errors in console. No error logs. Example chart in demo module works, C3 is installed.
What am I doing wrong?
Versions:
- Drupal: 8.4.2
- Charts: charts-8.x-3.0-alpha6