You are here

charts_highcharts.module in Charts 8

Same filename and directory in other branches
  1. 7.2 modules/charts_highcharts/charts_highcharts.module

Charts module integration with Highcharts library.

File

modules/charts_highcharts/charts_highcharts.module
View source
<?php

/**
 * @file
 * Charts module integration with Highcharts library.
 */
use Drupal\charts_highcharts\Settings\Highcharts\ChartType;
use Drupal\charts_highcharts\Settings\Highcharts\ChartTitle;
use Drupal\charts_highcharts\Settings\Highcharts\Xaxis;
use Drupal\charts_highcharts\Settings\Highcharts\ChartLabel;
use Drupal\charts_highcharts\Settings\Highcharts\YaxisLabel;
use Drupal\charts_highcharts\Settings\Highcharts\Yaxis;
use Drupal\charts_highcharts\Settings\Highcharts\YaxisTitle;
use Drupal\charts_highcharts\Settings\Highcharts\DataLabelStatus;
use Drupal\charts_highcharts\Settings\Highcharts\DataLabels;
use Drupal\charts_highcharts\Settings\Highcharts\PlotOptions;
use Drupal\charts_highcharts\Settings\Highcharts\Tooltip;
use Drupal\charts_highcharts\Settings\Highcharts\ChartCredits;
use Drupal\charts_highcharts\Settings\Highcharts\ChartLegend;
use Drupal\charts_highcharts\Settings\Highcharts\Highcharts;

/**
 * Implements hook_charts_info().
 */
function charts_highcharts_charts_info() {
  $info['highcharts'] = array(
    'label' => t('Highcharts'),
    'render' => '_charts_highcharts_render',
    'types' => array(
      'area',
      'bar',
      'column',
      'line',
      'pie',
      'scatter',
    ),
    'file' => 'charts_highcharts.inc',
  );
  return $info;
}

/**
 * Creates a JSON Object formatted for Highcharts to use
 *
 * @param $options
 * @param array $categories
 * @param array $seriesData
 *
 * @return Highcharts object to be used by highcharts javascripts visualization framework
 */
function charts_highcharts_render_charts($options, $categories = array(), $seriesData = array()) {
  $chart = new ChartType();
  $chart
    ->setType($options['type']);
  $chartTitle = new ChartTitle();
  $chartTitle
    ->setText($options['title']);
  $chartXaxis = new Xaxis();
  $chartLabels = new ChartLabel();
  $chartLabels
    ->setRotation($options['xaxis_labels_rotation']);
  $chartXaxis
    ->setCategories($categories);
  $chartTitle
    ->setText($options['title']);
  $chartXaxis
    ->setTitle($chartTitle);
  $chartXaxis
    ->setLabels($chartLabels);
  $yaxisLabels = new YaxisLabel();
  $chartYaxis = new Yaxis();
  $yAxisTitle = new YaxisTitle();
  $yAxisTitle
    ->setText($options['yaxis_title']);
  if (!empty($options['yaxis_min'])) {
    $chartYaxis->min = $options['yaxis_min'];
  }
  if (!empty($options['yaxis_max'])) {
    $chartYaxis->max = $options['yaxis_max'];
  }
  $chartYaxis
    ->setLabels($yaxisLabels);
  $chartYaxis
    ->setTitle($yAxisTitle);
  $dataLabelStatus = new DataLabelStatus();
  $dataLabels = new DataLabels();
  $dataLabels
    ->setDataLabels($dataLabelStatus);
  $barPlotOptns = new PlotOptions();
  $barPlotOptns
    ->setBar($dataLabels);
  $chartTooltip = new Tooltip();
  $chartCredits = new ChartCredits();
  $chartLegend = new ChartLegend();
  $highchart = new Highcharts();
  $highchart
    ->setChart($chart);
  $highchart
    ->setTitle($chartTitle);
  $highchart
    ->setXAxis($chartXaxis);
  $highchart
    ->setYAxis($chartYaxis);
  $highchart
    ->setTooltip($chartTooltip);
  $highchart
    ->setPlotOptions($barPlotOptns);
  $highchart
    ->setCredits($chartCredits);
  $highchart
    ->setLegend($chartLegend);
  $highchart
    ->setSeries($seriesData);
  return $highchart;
}

Functions

Namesort descending Description
charts_highcharts_charts_info Implements hook_charts_info().
charts_highcharts_render_charts Creates a JSON Object formatted for Highcharts to use