|
|
|
@ -128,7 +128,7 @@ export default {
|
|
|
|
|
return this.widgettext(params.chartProperties, data)
|
|
|
|
|
} else if (chartType == "widget-stackchart") {
|
|
|
|
|
return this.stackChartFn(params.chartProperties, data)
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
@ -161,8 +161,37 @@ export default {
|
|
|
|
|
return ananysicData;
|
|
|
|
|
},
|
|
|
|
|
//堆叠图
|
|
|
|
|
stackChartFn(chartProperties, data){
|
|
|
|
|
stackChartFn(chartProperties, data) {
|
|
|
|
|
const ananysicData = {};
|
|
|
|
|
const series = [];
|
|
|
|
|
//全部字段字典值
|
|
|
|
|
const types = Object.values(chartProperties)
|
|
|
|
|
//x轴字段、y轴字段名
|
|
|
|
|
const xAxisField = Object.keys(chartProperties)[types.indexOf('xAxis')]
|
|
|
|
|
const yAxisField = Object.keys(chartProperties)[types.indexOf('yAxis')]
|
|
|
|
|
//x轴数值去重,y轴去重
|
|
|
|
|
const xAxisList = this.setUnique(data.map(item => item[xAxisField]))
|
|
|
|
|
const yAxisList = this.setUnique(data.map(item => item[yAxisField]))
|
|
|
|
|
const dataGroup = this.setGroupBy(data, yAxisField)
|
|
|
|
|
|
|
|
|
|
for (const key in chartProperties) {
|
|
|
|
|
if (chartProperties[key] !== 'yAxis' && !chartProperties[key].startsWith('xAxis')) {
|
|
|
|
|
Object.keys(dataGroup).forEach(item => {
|
|
|
|
|
const data = new Array(yAxisList.length).fill(0)
|
|
|
|
|
dataGroup[item].forEach(res => {
|
|
|
|
|
data[xAxisList.indexOf(res[xAxisField])]= res[key]
|
|
|
|
|
})
|
|
|
|
|
series.push({
|
|
|
|
|
name: yAxisList[item],
|
|
|
|
|
type: chartProperties[key],
|
|
|
|
|
data,
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ananysicData["xAxis"] = xAxisList;
|
|
|
|
|
ananysicData["series"] = series;
|
|
|
|
|
return ananysicData;
|
|
|
|
|
},
|
|
|
|
|
// 饼图、漏斗图
|
|
|
|
|
piechartFn(chartProperties, data) {
|
|
|
|
@ -215,6 +244,24 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
return ananysicData;
|
|
|
|
|
},
|
|
|
|
|
setUnique(arr) {
|
|
|
|
|
let newArr = [];
|
|
|
|
|
arr.forEach(item => {
|
|
|
|
|
return newArr.includes(item) ? '' : newArr.push(item);
|
|
|
|
|
});
|
|
|
|
|
return newArr;
|
|
|
|
|
},
|
|
|
|
|
setGroupBy(array, name) {
|
|
|
|
|
const groups = {}
|
|
|
|
|
array.forEach(function (o) {
|
|
|
|
|
const group = JSON.stringify(o[name])
|
|
|
|
|
groups[group] = groups[group] || []
|
|
|
|
|
groups[group].push(o)
|
|
|
|
|
})
|
|
|
|
|
return Object.keys(groups).map(function (group) {
|
|
|
|
|
return groups[group]
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
'selectInput.keyname'(newVal, oldVal) {
|
|
|
|
|