diff --git a/includes/charts.pages.inc b/includes/charts.pages.inc index 947d6a0cd23d0ed59858bc8ec7a54340c323e749..9da38ea3cf32404ae47c57d6459609d1a0dc811c 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 6f80e9f9a14fc5b18d39b5863fbde050364a737e..45fe4bef879e69e21f91153e49dec522440e63ed 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 220be738e8b42c1404900e7e70ad70971559b44b..6104e733ca93200a580a01218c15ba76f6235e4b 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; }