The documentation on Drupal.behaviours suggests that local settings can be passed to Drupal's JavaScript behaviors.
Rather than hard coding my series data into my function:
series: [{
name: 'Jane',
data: [1, 5, 4]
}, {
name: 'John',
data: [3, 1, 2]
}]
how can I pass this series data to my function as settings, directly after the context?
JS code (my_highcharts.js)
(function ($) {
Drupal.behaviors.my_highcharts = {
attach: function (context, settings) {
$('#drupal_behaviours').highcharts({
chart: {
type: 'bar'
},
title: {
text: 'Drupal.behaviors'
},
colors: ['#50b432', '#ed561b'],
xAxis: {
categories: ['Apples', 'Bananas', 'Oranges']
},
yAxis: {
title: {
text: 'Fruit eaten'
}
},
series: [{
name: 'Jane',
data: [1, 5, 4]
}, {
name: 'John',
data: [3, 1, 2]
}]
});
}
};
})(jQuery);
Module code
drupal_add_js(drupal_get_path('module', 'my_highcharts') . '/highcharts.js');
return array('#markup' => '<div id="drupal_behaviours" style="width:100%; height:400px;"></div>');