You are here

function charts_c3_render_charts in Charts 8

1 call to charts_c3_render_charts()
template_preprocess_views_view_charts in ./charts.module

File

modules/charts_c3/charts_c3.module, line 26
Charts module integration with C3 library.

Code

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;
}