-
-
Save neetumorwani/2eb4c7eee277ba09fc704e0228f5814c to your computer and use it in GitHub Desktop.
Using highcharts with Drupal 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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