Skip to content

Instantly share code, notes, and snippets.

@neetumorwani
Forked from SebCorbin/mymodule.js
Created December 18, 2017 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neetumorwani/2eb4c7eee277ba09fc704e0228f5814c to your computer and use it in GitHub Desktop.
Save neetumorwani/2eb4c7eee277ba09fc704e0228f5814c to your computer and use it in GitHub Desktop.
Using highcharts with Drupal 7
(function ($) {
Drupal.behaviors.mymodule_charts = {
attach:function () {
if (Drupal.settings.mymodule.charts) {
for (var chart in Drupal.settings.mymodule.charts) {
new Highcharts.Chart(Drupal.settings.mymodule.charts[chart]);
}
}
}
};
})(jQuery);
<?php
/**
* Page callback
*/
function mymodule_stats() {
drupal_add_js(drupal_get_path('module', 'mymodule') . '/highcharts.js');
drupal_add_js(drupal_get_path('module', 'mymodule') . '/mymodule.js');
// Charting
$id = 'mychart';
$settings = array(
'chart' => array(
'renderTo' => 'chart-' . $id,
),
'xAxis' => array(
'categories' => array(1, 2, 3, 4, 5, 6, 7, 8, 9),
),
'title' => array(
'text' => 'Some title',
),
'series' => array(
array(
'name' => 'Data label',
'data' => array(1, 3, 7, 5, 6, 8, 9, 2, 3, 6),
),
),
'credits' => array(
'enabled' => FALSE,
),
);
drupal_add_js(array(array('charts' => array($id => $settings)), 'setting');
$content .= '<div id="chart-'. $id .'"></div>';
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment