diff --git a/client/app/visualizations/chart/chart-editor.html b/client/app/visualizations/chart/chart-editor.html
index 8f9c94e253..0ce6b2e4a9 100644
--- a/client/app/visualizations/chart/chart-editor.html
+++ b/client/app/visualizations/chart/chart-editor.html
@@ -9,9 +9,13 @@
Y Axis
-
+
Series
+
+ Colors
+
@@ -267,4 +271,36 @@
{{$index == 0 ? 'Left' : 'Right'}} Y Axis
+
+
+
+
+ zIndex |
+ Label |
+ Color |
+
+
+
+
+ |
+
+ {{name}}
+ |
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+
diff --git a/client/app/visualizations/chart/index.js b/client/app/visualizations/chart/index.js
index e2360cff3f..ed3c69e3e6 100644
--- a/client/app/visualizations/chart/index.js
+++ b/client/app/visualizations/chart/index.js
@@ -123,19 +123,48 @@ function ChartEditor(ColorPalette, clientConfig) {
}
function refreshSeries() {
- const seriesNames = pluck(scope.queryResult.getChartData(scope.options.columnMapping), 'name');
- const existing = keys(scope.options.seriesOptions);
- each(difference(seriesNames, existing), (name) => {
- scope.options.seriesOptions[name] = {
- type: scope.options.globalSeriesType,
- yAxis: 0,
- };
- scope.form.seriesList.push(name);
- });
- each(difference(existing, seriesNames), (name) => {
- scope.form.seriesList = without(scope.form.seriesList, name);
- delete scope.options.seriesOptions[name];
- });
+ // for pie charts only get color list (x row) instead of series list (y column)
+ if (scope.options.globalSeriesType === 'pie') {
+ const seriesData = scope.queryResult.getData();
+ scope.form.colorsList = [];
+ const xColumnName = scope.form.xAxisColumn;
+ seriesData.forEach((rowOfData) => {
+ scope.form.colorsList.push(rowOfData[xColumnName]);
+ });
+
+ const colorNames = scope.form.colorsList;
+ let existing = [];
+ if (scope.options.colorOptions === undefined) {
+ existing = colorNames;
+ } else {
+ existing = keys(scope.options.colorOptions);
+ }
+ each(difference(colorNames, existing), (name) => {
+ scope.options.colorOptions[name] = {
+ type: scope.options.globalSeriesType,
+ yAxis: 0,
+ };
+ scope.form.colorsList.push(name);
+ });
+ each(difference(existing, colorNames), (name) => {
+ scope.form.colorsList = without(scope.form.colorsList, name);
+ delete scope.options.colorOptions[name];
+ });
+ } else {
+ const seriesNames = pluck(scope.queryResult.getChartData(scope.options.columnMapping), 'name');
+ const existing = keys(scope.options.seriesOptions);
+ each(difference(seriesNames, existing), (name) => {
+ scope.options.seriesOptions[name] = {
+ type: scope.options.globalSeriesType,
+ yAxis: 0,
+ };
+ scope.form.seriesList.push(name);
+ });
+ each(difference(existing, seriesNames), (name) => {
+ scope.form.seriesList = without(scope.form.seriesList, name);
+ delete scope.options.seriesOptions[name];
+ });
+ }
}
function setColumnRole(role, column) {
@@ -167,6 +196,8 @@ function ChartEditor(ColorPalette, clientConfig) {
yAxisColumns: [],
seriesList: sortBy(keys(scope.options.seriesOptions), name =>
scope.options.seriesOptions[name].zIndex),
+ colorsList: sortBy(keys(scope.options.colorOptions), name =>
+ scope.options.colorOptions[name].zIndex),
};
scope.$watchCollection('form.seriesList', (value) => {
@@ -176,7 +207,6 @@ function ChartEditor(ColorPalette, clientConfig) {
});
});
-
scope.$watchCollection('form.yAxisColumns', (value, old) => {
each(old, unsetColumn);
each(value, partial(setColumnRole, 'y'));
diff --git a/client/app/visualizations/chart/plotly/utils.js b/client/app/visualizations/chart/plotly/utils.js
index 6fe28533ca..bdbeb0f1a5 100644
--- a/client/app/visualizations/chart/plotly/utils.js
+++ b/client/app/visualizations/chart/plotly/utils.js
@@ -183,9 +183,17 @@ function preparePieData(seriesList, options) {
return map(seriesList, (serie, index) => {
const xPosition = (index % cellsInRow) * cellWidth;
const yPosition = Math.floor(index / cellsInRow) * cellHeight;
+ const labels = map(serie.data, (row, rowIdx) => {
+ const rowX = hasX ? row.x : `Slice ${index}`;
+ const rowOpts = options.seriesOptions[rowX];
+ if (rowOpts) {
+ colorPalette[rowIdx] = rowOpts.color;
+ }
+ return rowX;
+ });
return {
values: pluck(serie.data, 'y'),
- labels: map(serie.data, row => (hasX ? row.x : `Slice ${index}`)),
+ labels: labels,
type: 'pie',
hole: 0.4,
marker: { colors: ColorPaletteArray },