I am running Drupal 9 in Lando. I have enabled the Charts and Highcharts modules and installed the Highcharts JS library with composer. I wrote a simple module to display a Pie Chart but the chart won't display. My code is below. Do you see any glaring errors or ways I can debug this? I ported this from an example that runs fine in D7 in DevDesktop.
The info yaml file.
name: My Test Chart
description: This is an example use of the Charts module.
package: Custom
type: module
core_version_requirement: ^9
dependencies:
- chart
The router yaml file.
example_chart:
path: 'mychart-example'
defaults:
_title: 'My Example Chart'
_controller: '\Drupal\mychart\Controller\MyChartController::example_page'
requirements:
_permission: 'access content'
The library yaml file.
highcharts:
js:
libraries/highcharts/highcharts.js: { }
dependencies:
- core/jquery
The Controller.
namespace Drupal\mychart\Controller;
use Drupal\Core\Controller\ControllerBase;
class MyChartController extends ControllerBase {
/**
* @return array
*/
function example_page() {
$chart = array(
'#attached' => array(
'library' => array('mychart/highcharts'),
),
'#type' => 'chart',
'#chart_type' => 'pie',
'#chart_library' => 'highcharts',
'#title' => t('Simple Pie Chart'),
);
$chart['pie_data'] = array(
'#type' => 'chart_data',
'#title' => t('Gender'),
'#data' => array(array('Male', 10), array('Female', 20)),
);
return $chart;
}
}