From 4f9a33ecdaba5b06e0714b1023f94683582cdb58 Mon Sep 17 00:00:00 2001
From: Daniel Cothran <daniel@andile.co>
Date: Mon, 12 Feb 2018 18:14:57 -0500
Subject: [PATCH] Issue #2944095 by John Cook: The Pie chart example does not
 work with Highcharts

---
 includes/charts.pages.inc                     |  6 ++-
 .../src/Controller/ChartsApiExample.php       | 41 +++++++++++--------
 src/Form/ChartsConfigForm.php                 |  6 ++-
 3 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/includes/charts.pages.inc b/includes/charts.pages.inc
index 947d6a0..9da38ea 100644
--- a/includes/charts.pages.inc
+++ b/includes/charts.pages.inc
@@ -116,6 +116,10 @@ function charts_charts_type_info() {
       'label' => t('Scatter'),
       'axis'  => ChartsInterface::CHARTS_DUAL_AXIS,
     ],
+    'donut' => [
+      'label' => t('Donut'),
+      'axis' => ChartsInterface::CHARTS_SINGLE_AXIS,
+    ],
   ];
 }
 
@@ -669,7 +673,7 @@ function charts_default_settings_form_submit($form, $form_state) {
  */
 function charts_default_settings() {
   $defaults = [
-    'type'                  => 'pie',
+    'type'                  => 'line',
     'library'               => NULL,
     'label_field'           => NULL,
     'data_fields'           => NULL,
diff --git a/modules/charts_api_example/src/Controller/ChartsApiExample.php b/modules/charts_api_example/src/Controller/ChartsApiExample.php
index 6f80e9f..45fe4be 100644
--- a/modules/charts_api_example/src/Controller/ChartsApiExample.php
+++ b/modules/charts_api_example/src/Controller/ChartsApiExample.php
@@ -49,24 +49,31 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter
 
     // Sample data format.
     $categories = ['Category 1', 'Category 2', 'Category 3', 'Category 4'];
-    $seriesData = [
-      [
-        'name'  => 'Series 1',
-        'color' => '#0d233a',
-        'type'  => NULL,
-        'data'  => [250, 350, 400, 200],
-      ], [
-        'name'  => 'Series 2',
-        'color' => '#8bbc21',
-        'type'  => 'column',
-        'data'  => [150, 450, 500, 300],
-      ], [
-        'name'  => 'Series 3',
-        'color' => '#910000',
-        'type'  => 'area',
-        'data'  => [0, 0, 60, 90],
-      ],
+    $seriesData[] = [
+      'name'  => 'Series 1',
+      'color' => '#0d233a',
+      'type'  => NULL,
+      'data'  => [250, 350, 400, 200],
     ];
+    switch ($this->chartSettings['type']) {
+      default:
+        $seriesData[] = [
+          'name'  => 'Series 2',
+          'color' => '#8bbc21',
+          'type'  => 'column',
+          'data'  => [150, 450, 500, 300],
+          ];
+        $seriesData[] = [
+          'name'  => 'Series 3',
+          'color' => '#910000',
+          'type'  => 'area',
+          'data'  => [0, 0, 60, 90],
+        ];
+      // If using C3, comment out the following two cases.
+      case 'pie':
+      case 'donut':
+        
+    }
 
     $build = [
       '#theme'      => 'charts_api_example',
diff --git a/src/Form/ChartsConfigForm.php b/src/Form/ChartsConfigForm.php
index 220be73..6104e73 100644
--- a/src/Form/ChartsConfigForm.php
+++ b/src/Form/ChartsConfigForm.php
@@ -104,7 +104,7 @@ class ChartsConfigForm extends ConfigFormBase {
    */
   public function chartsDefaultSettings() {
     $defaults = [
-      'type'                  => 'pie',
+      'type'                  => 'line',
       'library'               => NULL,
       'label_field'           => NULL,
       'data_fields'           => NULL,
@@ -577,6 +577,10 @@ class ChartsConfigForm extends ConfigFormBase {
       'label' => $this->t('Scatter'),
       'axis' => ChartsInterface::CHARTS_DUAL_AXIS,
     ];
+    $chart_types['donut'] = [
+      'label' => $this->t('Donut'),
+      'axis' => ChartsInterface::CHARTS_SINGLE_AXIS,
+    ];
 
     return $chart_types;
   }
-- 
GitLab