折线对比图图例

qianming 3 years ago
parent dd1ff18548
commit 46dde2ccfc

@ -533,9 +533,9 @@ export default {
const legend = this.options.legend; const legend = this.options.legend;
legend.show = optionsSetup.isShowLegend; legend.show = optionsSetup.isShowLegend;
legend.left = optionsSetup.lateralPosition; legend.left = optionsSetup.lateralPosition;
legend.top = optionsSetup.longitudinalPosition == "top" ? 0 : "auto"; legend.top = optionsSetup.longitudinalPosition;
legend.bottom = legend.bottom =
optionsSetup.longitudinalPosition == "bottom" ? 0 : "auto"; optionsSetup.longitudinalPosition;
legend.orient = optionsSetup.layoutFront; legend.orient = optionsSetup.layoutFront;
legend.textStyle = { legend.textStyle = {
color: optionsSetup.lengedColor, color: optionsSetup.lengedColor,
@ -543,6 +543,25 @@ export default {
}; };
legend.itemWidth = optionsSetup.lengedWidth; legend.itemWidth = optionsSetup.lengedWidth;
}, },
//
setOptionsLegendName(name){
const optionsSetup = this.optionsSetup;
const series = this.options.series;
const legendName = optionsSetup.legendName;
//
if (null == legendName || legendName == '') {
for (let i = 0; i < name.length; i++) {
series[i].name = name[i];
}
this.options.legend['data'] = name;
}else {
const arr = legendName.split('|');
for (let i = 0; i < arr.length; i++) {
series[i].name = arr[i];
}
this.options.legend['data'] = arr
}
},
// //
setOptionsColor() { setOptionsColor() {
const optionsSetup = this.optionsSetup; const optionsSetup = this.optionsSetup;
@ -591,19 +610,20 @@ export default {
let xAxisList = []; let xAxisList = [];
let yAxisList = []; let yAxisList = [];
let arrayList = []; let arrayList = [];
const legendName = [];
for (const i in val) { for (const i in val) {
xAxisList[i] = val[i].axis xAxisList[i] = val[i].axis;
yAxisList[i] = val[i].name yAxisList[i] = val[i].name;
} }
xAxisList = this.setUnique(xAxisList) xAxisList = this.setUnique(xAxisList);
yAxisList = this.setUnique(yAxisList) yAxisList = this.setUnique(yAxisList);
for (const i in yAxisList) { for (const i in yAxisList) {
const data = new Array(yAxisList.length).fill(0) const data = new Array(yAxisList.length).fill(0);
for (const j in xAxisList) { for (const j in xAxisList) {
for (const k in val) { for (const k in val) {
if (val[k].name == yAxisList[i]) { if (val[k].name == yAxisList[i]) {
if (val[k].axis == xAxisList[j]) { if (val[k].axis == xAxisList[j]) {
data[j] = val[k].data data[j] = val[k].data;
} }
} }
} }
@ -612,13 +632,16 @@ export default {
name: yAxisList[i], name: yAxisList[i],
data: data data: data
}) })
legendName.push(yAxisList[i]);
} }
this.options.series[0]['name'] = arrayList[0].name this.options.series[0]['name'] = arrayList[0].name;
this.options.series[0]['data'] = arrayList[0].data this.options.series[0]['data'] = arrayList[0].data;
this.options.series[1]['name'] = arrayList[1].name this.options.series[1]['name'] = arrayList[1].name;
this.options.series[1]['data'] = arrayList[1].data this.options.series[1]['data'] = arrayList[1].data;
this.options.xAxis[0]['data'] = xAxisList this.options.xAxis[0]['data'] = xAxisList;
this.options.xAxis[1]['data'] = xAxisList this.options.xAxis[1]['data'] = xAxisList;
this.options.legend['data'] = legendName;
this.setOptionsLegendName(legendName);
}, },
// //
dynamicDataFn(val, refreshTime, optionsSetup) { dynamicDataFn(val, refreshTime, optionsSetup) {
@ -639,14 +662,19 @@ export default {
}); });
}, },
renderingFn(optionsSetup, val) { renderingFn(optionsSetup, val) {
this.options.xAxis[0]['data'] = val.xAxis const legendName = [];
this.options.xAxis[1]['data'] = val.xAxis this.options.xAxis[0]['data'] = val.xAxis;
this.options.xAxis[1]['data'] = val.xAxis;
if (val.series[0].type == "line") { if (val.series[0].type == "line") {
this.options.series[0]['name'] = val.series[0].name this.options.series[0]['name'] = val.series[0].name;
this.options.series[0]['data'] = val.series[0].data this.options.series[0]['data'] = val.series[0].data;
this.options.series[1]['name'] = val.series[1].name this.options.series[1]['name'] = val.series[1].name;
this.options.series[1]['data'] = val.series[1].data this.options.series[1]['data'] = val.series[1].data;
legendName.push(val.series[0].name);
legendName.push(val.series[1].name);
} }
this.options.legend['data'] = legendName;
this.setOptionsLegendName(legendName);
} }
} }
}; };

Loading…
Cancel
Save