function _easychart_print_chart in Easychart 7.3
Same name and namespace in other branches
- 7 easychart.module \_easychart_print_chart()
- 7.2 easychart.module \_easychart_print_chart()
Helper functions to print the actual chart.
Parameters
$item: The item
$delta: The delta.
Return value
string $output
1 call to _easychart_print_chart()
- easychart_field_formatter_view in ./
easychart.module - Implements hook_field_formatter_view().
File
- ./
easychart.module, line 402 - Easychart module file.
Code
function _easychart_print_chart($item, $delta) {
global $chart_count;
$chart_count++;
$output = '';
if (!empty($item['config'])) {
if ($chart_count == 1) {
// Add the highcharts javascript.
libraries_load('highcharts');
libraries_load('easychart', 'render');
}
// Print a div and add inline javascript
$output = '<div id="easychart-chart-' . $chart_count . '">';
$output .= '</div>';
// Get the csv data.
$csv = '';
if (!empty($item['csv'])) {
$csv = $item['csv'];
}
$inline_js = ' document.addEventListener("DOMContentLoaded", function () {
var container = document.getElementById(\'easychart-chart-' . $chart_count . '\');
window.easychart = new ec({element: container});';
$inline_js .= ' window.easychart.setConfigStringified(\'' . $item['config'] . '\');';
$inline_js .= ' window.easychart.setData(' . $csv . ');';
if (variable_get('easychart_presets', '') != '') {
$inline_js .= ' window.easychart.setPresets(' . str_replace('\\r\\n', '', variable_get('easychart_presets', '')) . ');';
}
$inline_js .= '})';
drupal_add_js($inline_js, array(
'type' => 'inline',
'scope' => 'footer',
));
}
return $output;
}