You are here

function _easychart_print_chart in Easychart 7

Same name and namespace in other branches
  1. 7.3 easychart.module \_easychart_print_chart()
  2. 7.2 easychart.module \_easychart_print_chart()
1 call to _easychart_print_chart()
easychart_field_formatter_view in ./easychart.module
Implements hook_field_formatter_view().

File

./easychart.module, line 301
Easy Chart 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');

      // Add the easychart javascript.
      drupal_add_js(drupal_get_path('module', 'easychart') . '/js/easychart.js');
    }

    // Print a div and add inline javascript
    $output = '<div class="easychart-chart-' . $chart_count . '">';
    $output .= '</div>';

    // Get the csv data.
    if (!empty($item['csv_url'])) {
      $csv = file_get_contents($item['csv_url']);
    }
    else {
      if (!empty($item['csv'])) {
        $csv = $item['csv'];
      }
    }
    $csv = str_replace("\r\n", 'EC_EOL', $csv);
    $csv = str_replace("\n", 'EC_EOL', $csv);
    drupal_add_js('Drupal.behaviors.easyChart_' . $chart_count . ' = { attach: function() { if (jQuery(".easychart-chart-' . $chart_count . '").length > 0) { var options = ' . $item['config'] . '; options = _preprocessHighchartsData(options, "' . $csv . '"); jQuery(".easychart-chart-' . $chart_count . '").highcharts(options);}}};', array(
      'type' => 'inline',
      'scope' => 'footer',
    ));
  }
  return $output;
}