Skip to content
Snippets Groups Projects
Commit 0330f6f5 authored by Daniel Cothran's avatar Daniel Cothran
Browse files

Issue #2947190 by zinalacina, andileco: C3 Charts donut Chart Doesn't Render Properly

parent 934ce6f6
No related branches found
No related tags found
No related merge requests found
......@@ -51,12 +51,13 @@ class C3 extends AbstractChart {
}
/**
* Depending on the number of data fields, the charts will either use data
* fields or label fields for the categories. If only one data field is
* selected, then the label field will serve as the categories. If multiple
* data fields are selected, they will become the categories.
* For pie and donut chart types, depending on the number of data fields,
* the charts will either use data fields or label fields for the
* categories. If only one data field is selected, then the label field
* will serve as the categories. If multiple data fields are selected,
* they will become the categories.
* */
if ($options['type'] == 'pie' || $options['type'] == 'donut' ) {
if ($options['type'] == 'pie' || $options['type'] == 'donut') {
if (count($seriesData) > 1) {
$c3Data = [];
for ($i = 0; $i < count($seriesData); $i++) {
......@@ -82,8 +83,7 @@ class C3 extends AbstractChart {
array_push($c3Data, $c3DataTemp);
}
}
$c3Chart = new ChartType();
$c3Chart->setType($options['type']);
$c3ChartTitle = new ChartTitle();
......
......@@ -46,23 +46,63 @@ class Google extends AbstractChart {
array_push($dataCount, $dataCountTemp);
}
$dataTable = [];
for ($j = 0; $j < $categoriesCount; $j++) {
$rowDataTable = [];
for ($i = 0; $i < $seriesCount; $i++) {
$rowDataTabletemp = $seriesData[$i]['data'][$j];
array_push($rowDataTable, $rowDataTabletemp);
/**
* For pie and donut chart types, depending on the number of data fields,
* the charts will either use data fields or label fields for the
* categories. If only one data field is selected, then the label field
* will serve as the categories. If multiple data fields are selected,
* they will become the categories.
* */
if ($options['type'] == 'pie' || $options['type'] == 'donut') {
if ($seriesCount > 1) {
$dataTable = [];
for ($j = 0; $j < $seriesCount; $j++) {
$rowDataTable = [];
$rowDataTabletemp = array_sum($seriesData[$j]['data']);
array_push($rowDataTable, $rowDataTabletemp);
array_unshift($rowDataTable, $seriesData[$j]['name']);
array_push($dataTable, $rowDataTable);
}
$dataTableHeader = ['label','value'];
array_unshift($dataTable, $dataTableHeader);
}
else {
$dataTable = [];
for ($j = 0; $j < $categoriesCount; $j++) {
$rowDataTable = [];
for ($i = 0; $i < $seriesCount; $i++) {
$rowDataTabletemp = $seriesData[$i]['data'][$j];
array_push($rowDataTable, $rowDataTabletemp);
}
array_unshift($rowDataTable, $categories[$j]);
array_push($dataTable, $rowDataTable);
}
$dataTableHeader = [];
for ($r = 0; $r < $seriesCount; $r++) {
array_push($dataTableHeader, $seriesData[$r]['name']);
}
array_unshift($dataTableHeader, 'label');
array_unshift($dataTable, $dataTableHeader);
}
array_unshift($rowDataTable, $categories[$j]);
array_push($dataTable, $rowDataTable);
}
$dataTableHeader = [];
for ($r = 0; $r < $seriesCount; $r++) {
array_push($dataTableHeader, $seriesData[$r]['name']);
else {
$dataTable = [];
for ($j = 0; $j < $categoriesCount; $j++) {
$rowDataTable = [];
for ($i = 0; $i < $seriesCount; $i++) {
$rowDataTabletemp = $seriesData[$i]['data'][$j];
array_push($rowDataTable, $rowDataTabletemp);
}
array_unshift($rowDataTable, $categories[$j]);
array_push($dataTable, $rowDataTable);
}
$dataTableHeader = [];
for ($r = 0; $r < $seriesCount; $r++) {
array_push($dataTableHeader, $seriesData[$r]['name']);
}
array_unshift($dataTableHeader, 'label');
array_unshift($dataTable, $dataTableHeader);
}
array_unshift($dataTableHeader, 'label');
array_unshift($dataTable, $dataTableHeader);
$googleOptions = $this->createChartsOptions($options, $seriesData, $attachmentDisplayOptions);
$googleChartType = $this->createChartType($options);
......@@ -72,7 +112,6 @@ class Google extends AbstractChart {
$variables['content_attributes']['data-chart'][] = json_encode($dataTable);
$variables['attributes']['google-options'][1] = json_encode($googleOptions);
$variables['attributes']['google-chart-type'][2] = json_encode($googleChartType);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment