diff --git a/views/charts_plugin_style_chart.inc b/views/charts_plugin_style_chart.inc index 2e45b5f..2fb9ac0 100644 --- a/views/charts_plugin_style_chart.inc +++ b/views/charts_plugin_style_chart.inc @@ -244,6 +244,8 @@ class charts_plugin_style_chart extends views_plugin_style { // from before the grouping, so we need to keep our own row number when // looping through the rows. $row_number = 0; + $data = array(); + $xaxis_labels = $chart['xaxis']['#labels']; foreach ($data_set['rows'] as $result_number => $row) { if ($label_field_key && !isset($chart['xaxis']['#labels'][$row_number])) { $chart['xaxis']['#labels'][$row_number] = $this->get_field($result_number, $label_field_key); @@ -263,10 +265,18 @@ class charts_plugin_style_chart extends views_plugin_style { else { $value = (float) str_replace(array(',', ' '), '', $value); } - $chart[$series_key]['#data'][] = $value; + $data[$this->get_field($result_number, $label_field_key)] = $value; } $row_number++; } + foreach ($xaxis_labels as $id => $label) { + if (isset($data[$label])) { + $chart[$series_key]['#data'][$id] = $data[$label]; + } + else { + $chart[$series_key]['#data'][$id] = 0; + } + } } } @@ -318,6 +328,18 @@ class charts_plugin_style_chart extends views_plugin_style { // Merge in the child chart data. foreach (element_children($subchart) as $key) { if ($subchart[$key]['#type'] === 'chart_data') { + $data = array(); + $subchart_xaxis_labels = $subchart['xaxis']['#labels']; + foreach ($chart['xaxis']['#labels'] as $id => $label) { + $index = array_search($label, $subchart_xaxis_labels); + if ($index === FALSE) { + $data[$id] = 0; + } + else { + $data[$id] = $subchart[$key]['#data'][$index]; + } + } + $subchart[$key]['#data'] = $data; $chart[$key] = $subchart[$key]; // If the subchart is a different type than the parent chart, set // the #chart_type property on the individual chart data elements.