Skip to content

Commit 0b0b38b

Browse files
committed
[ui-vuejs] Better chart barChart and stackedBarChart
1 parent 10bbe97 commit 0b0b38b

File tree

5 files changed

+103
-72
lines changed

5 files changed

+103
-72
lines changed

vertigo-ui-vuejs/src/components/dashboard/VDashboardChart.vue

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,23 @@ const verticalLinePlugin = {
7171
export default {
7272
props : {
7373
title: { type: String, },
74-
type: { type: String, required: true },
75-
datas: { type: Array, },
74+
type: { type: String, required: true },
75+
datas: { type: Object, },
7676
dataSeriesTranslator: { type: Function,},
7777
queryUrl: { type: String, },
7878
queryClusteredMeasure: { type: Object, },
7979
queryMeasures: { type: Array, },
8080
queryDataFilter: { type: Object, },
8181
queryTimeFilter: { type: Object, },
8282
queryGroupBy: { type: String, },
83-
colors: { type: String, required: true, default:'DEFAULT' },
84-
labels: { type: Object, required: true },
83+
colors: { type: String, default:'DEFAULT' },
84+
labels: { type: Object, required: true },
8585
minTime: { type: String, },
8686
maxTime: { type: String, },
8787
fillGapDim: { type: String, },
8888
fillGapValue: { type: Number, },
89-
timeFormat: { type: String, required: true, default:'DD/MM/YYYY HH:mm' },
90-
verticalLines: { type: Array, }, /** {x, label, color} */
89+
timeFormat: { type: String, default:'DD/MM/YYYY HH:mm' },
90+
verticalLines: { type: Array, }, /** {x, label, color} */
9191
additionalOptions: { type: Object, },
9292
},
9393
created : function () {
@@ -198,17 +198,23 @@ export default {
198198
var bubblesData = this.toChartJsBubblesData(datas, realLabels.keys(), realLabels, queryGroupBy);
199199
chartJsDataSets = [ {data: bubblesData }];
200200
chartOptions = this.getChartJsBubblesOptions(datas, realLabels.keys(), queryGroupBy, realLabels, chartTitle, additionalOptions);
201-
this.setChartJsColorOptions(chartJsDataSets, dataColors, 0.5);
201+
this.setChartJsColorOptions(chartJsDataSets, dataColors, 1, 0.5);
202202
} else if (this.type ==="linechart") {
203203
chartJsType = 'line';
204204
chartJsDataSets = this.toChartJsData(datas, dataLabels, timedSeries, queryGroupBy);
205205
chartOptions = this.getChartJsLineOptions(datas, queryGroupBy, dataLabels, timedSeries, chartTitle, additionalOptions);
206206
this.setChartJsColorOptions(chartJsDataSets, dataColors);
207-
} else if (this.type ==="stakedbarchart") {
207+
} else if (this.type ==="barchart") {
208208
chartJsType = 'bar';
209209
chartJsDataSets = this.toChartJsData(datas, dataLabels, timedSeries, queryGroupBy);
210+
chartOptions = this.getChartJsLineOptions(datas, queryGroupBy, dataLabels, timedSeries, chartTitle, additionalOptions);
211+
this.setChartJsColorOptions(chartJsDataSets, dataColors, 1, 0.5);
212+
} else if (this.type ==="stackedbarchart") {
213+
chartJsType = 'bar';
214+
chartJsDataSets = this.toChartJsData(datas, dataLabels, timedSeries, queryGroupBy);
215+
//chartOptions = this.getChartJsLineOptions(datas, queryGroupBy, dataLabels, timedSeries, chartTitle, additionalOptions);
210216
chartOptions = this.getStackedOptions(datas, queryGroupBy, dataLabels, timedSeries, chartTitle, additionalOptions);
211-
this.setChartJsColorOptions(chartJsDataSets, dataColors);
217+
this.setChartJsColorOptions(chartJsDataSets, dataColors, 1, 0.5);
212218
} else if (this.type ==="polararea") {
213219
chartJsType = 'polarArea';
214220
chartJsDataSets = this.toChartJsData(datas, dataLabels, timedSeries, queryGroupBy);
@@ -259,10 +265,10 @@ export default {
259265
graphChart.update("none");
260266
}
261267
},
262-
setChartJsColorOptions: function(datasets, dataColors, opacity) {
268+
setChartJsColorOptions: function(datasets, dataColors, opacity, bgOpacity) {
263269
if(dataColors) {
264270
var myColors = getColors(dataColors, datasets.length, opacity);
265-
var myBgColors = getColors(dataColors, datasets.length, opacity?opacity*0.25:0.25);
271+
var myBgColors = getColors(dataColors, datasets.length, bgOpacity?bgOpacity:(opacity?opacity*0.25:0.25));
266272
for(var i = 0 ; i<datasets.length; i++) {
267273
datasets[i].borderColor = myColors[i];
268274
datasets[i].backgroundColor = myBgColors[i];
@@ -404,6 +410,9 @@ export default {
404410
},
405411
line : {
406412
tension: 0
413+
},
414+
bar : {
415+
borderWidth: 3
407416
}
408417
}
409418
};
@@ -440,10 +449,18 @@ export default {
440449
441450
442451
getStackedOptions: function(datas, queryGroupBy, dataLabels, timedSeries, chartTitle, additionalOptions){
443-
var options = this.getChartJsLineOptions(datas, dataQuery, dataLabels, timedSeries, additionalOptions)
444-
options.scales.x.stacked = true;
445-
options.scales.y.stacked = true;
446-
return options;
452+
var options = this.getChartJsLineOptions(datas, queryGroupBy, dataLabels, timedSeries, chartTitle, additionalOptions);
453+
var stackedOptions = {
454+
scales : {
455+
x: {
456+
stacked: true
457+
},
458+
y: {
459+
stacked: true
460+
}
461+
}
462+
};
463+
return this.mergeDeep(options, stackedOptions);
447464
},
448465
449466

0 commit comments

Comments
 (0)