charts_c3.module in Charts 8
Charts module integration with C3 library.
File
modules/charts_c3/charts_c3.moduleView source
<?php
/**
* @file
* Charts module integration with C3 library.
*/
use Drupal\charts_c3\Settings\CThree\ChartType;
use Drupal\charts_c3\Settings\CThree\CThree;
use Drupal\charts_c3\Settings\CThree\ChartTitle;
use Drupal\charts_c3\Settings\CThree\ChartData;
use Drupal\charts_c3\Settings\CThree\ChartColor;
use Drupal\charts_c3\Settings\CThree\ChartAxis;
/**
* Implements hook_charts_info().
*/
function charts_c3_charts_info() {
$info['c3'] = array(
'label' => t('C3 Charts'),
'types' => array(
'area',
'bar',
'column',
'line',
'pie',
'scatter',
),
);
return $info;
}
function charts_c3_render_charts($options, $categories = array(), $seriesData = array(), $chartId) {
$c3Data = array();
for ($i = 0; $i < count($seriesData); $i++) {
$c3DataTemp = $seriesData[$i]['data'];
array_unshift($c3DataTemp, $seriesData[$i]['name']);
array_push($c3Data, $c3DataTemp);
}
$c3Chart = new ChartType();
$c3Chart
->setType($options['type']);
$c3ChartTitle = new ChartTitle();
$c3ChartTitle
->setText($options['title']);
$chartAxis = new ChartAxis();
$c3 = new CThree();
$bindTo = '#' . $chartId;
$c3
->setBindTo($bindTo);
//$c3->setChart($c3Chart);
//$c3->setLabels($options['data_labels']);
$c3
->setTitle($c3ChartTitle);
$chartData = new ChartData();
$chartData
->setType($options['type']);
$c3
->setData($chartData);
if ($options['type'] == 'bar') {
$chartAxis
->setRotated(TRUE);
array_unshift($categories, 'x');
array_push($c3Data, $categories);
$chartData
->setColumns($c3Data);
}
else {
if ($options['type'] == 'column') {
$chartData
->setType('bar');
$chartAxis
->setRotated(FALSE);
array_unshift($categories, 'x');
array_push($c3Data, $categories);
$chartData
->setColumns($c3Data);
}
else {
array_unshift($categories, 'x');
array_push($c3Data, $categories);
$chartData
->setColumns($c3Data);
}
}
$c3
->setAxis($chartAxis);
$chartColor = new ChartColor();
$seriesColors = array();
for ($i = 0; $i < count($seriesData); $i++) {
$seriesColor = $seriesData[$i]['color'];
array_push($seriesColors, $seriesColor);
}
$chartColor
->setPattern($seriesColors);
$c3
->setColor($chartColor);
return $c3;
}
Functions
Name | Description |
---|---|
charts_c3_charts_info | Implements hook_charts_info(). |
charts_c3_render_charts |