Skip to content

Instantly share code, notes, and snippets.

@SebCorbin
Created March 6, 2012 21:53
Show Gist options
  • Save SebCorbin/1989168 to your computer and use it in GitHub Desktop.
Save SebCorbin/1989168 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;
}
@joeland
Copy link

joeland commented Aug 10, 2015

Hello,
I need some help I want to build a chart from only one content Type with many author and sort by Autor for each Year. I'm using Hightchart with drupal but the result I get is not good. So can I have your advise?
CT (Statisitque) - Fields [Value(Integer), Date(Month & Year), Author()]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment