bugfix-多柱线图图例和颜色对应不上

qianming 2 years ago
parent 782f9435e8
commit 31a9b860a8

@ -80,6 +80,18 @@ export const widgetBarlinechart = {
placeholder: '', placeholder: '',
value: 5, value: 5,
}, },
{
type: 'el-select',
label: '点样式',
name: 'symbol',
required: false,
placeholder: '',
selectOptions: [
{code: 'circle', name: '实心点'},
{code: 'emptyCircle', name: '空心点'},
],
value: 'circle'
},
{ {
type: 'el-switch', type: 'el-switch',
label: '平滑曲线', label: '平滑曲线',
@ -855,7 +867,7 @@ export const widgetBarlinechart = {
label: '', label: '',
name: 'customColor', name: 'customColor',
required: false, required: false,
value: [{color: '#00F4FFFF'}, {color: '#e68b55'}], value: [{color: '#ff7f50'}, {color: '#87cefa'}, {color: '#da70d6'}, {color: '#32cd32'}, {color: '#6495ed'}],
}, },
], ],
}, },

@ -72,6 +72,18 @@ export const widgetMoreBarLine = {
placeholder: '', placeholder: '',
value: 3, value: 3,
}, },
{
type: 'el-select',
label: '点样式',
name: 'symbol',
required: false,
placeholder: '',
selectOptions: [
{code: 'circle', name: '实心点'},
{code: 'emptyCircle', name: '空心点'},
],
value: 'circle'
},
{ {
type: 'el-switch', type: 'el-switch',
label: '平滑曲线', label: '平滑曲线',
@ -847,11 +859,7 @@ export const widgetMoreBarLine = {
label: '', label: '',
name: 'customColor', name: 'customColor',
required: false, required: false,
value: [ value: [{color: '#ff7f50'}, {color: '#87cefa'}, {color: '#da70d6'}, {color: '#32cd32'}, {color: '#6495ed'}],
{color: '#4bdfff'},
{color: '#55f49c'},
{color: '#ffa43a'},
],
}, },
], ],
}, },

@ -303,6 +303,7 @@ export default {
const series = this.options.series; const series = this.options.series;
for (const key in series) { for (const key in series) {
if (series[key].type == "line") { if (series[key].type == "line") {
series[key].symbol = optionsSetup.symbol;
series[key].showSymbol = optionsSetup.markPoint; series[key].showSymbol = optionsSetup.markPoint;
series[key].symbolSize = optionsSetup.pointSize; series[key].symbolSize = optionsSetup.pointSize;
series[key].smooth = optionsSetup.smoothCurve; series[key].smooth = optionsSetup.smoothCurve;

@ -31,17 +31,7 @@ export default {
top: '16%', top: '16%',
containLabel: true containLabel: true
}, },
legend: { legend: {},
data: ['调解成功', '调解失败', '调解终止', '调解成功率'],
left: '7%',
top: '5%',
textStyle: {
color: '#666666'
},
itemWidth: 15,
itemHeight: 10,
itemGap: 25
},
xAxis: { xAxis: {
type: 'category', type: 'category',
data: ['2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019'], data: ['2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019'],
@ -132,23 +122,6 @@ export default {
}, },
data: [] data: []
}, },
{
name: '调解终止',
type: 'bar',
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: '#01c871'
}, {
offset: 1,
color: '#55f49c'
}]),
barBorderRadius: 6,
}
},
data: []
},
{ {
name: '调解成功率', name: '调解成功率',
type: 'line', type: 'line',
@ -156,14 +129,13 @@ export default {
smooth: false, //线 smooth: false, //线
symbol: 'circle', // symbol: 'circle', //
symbolSize: 8, // symbolSize: 8, //
itemStyle: { /*itemStyle: {
normal: { normal: {
color: '#ffa43a', color: '#ffa43a',
borderColor: 'rgba(255, 234, 0, 0.5)', // borderColor: 'rgba(255, 234, 0, 0.5)', //
borderWidth: 5 borderWidth: 5
}, },
},*/
},
lineStyle: { lineStyle: {
color: '#ffa43a' color: '#ffa43a'
}, },
@ -213,7 +185,6 @@ export default {
this.setOptionsLegend(); this.setOptionsLegend();
this.setOptionsTooltip(); this.setOptionsTooltip();
this.setOptionsMargin(); this.setOptionsMargin();
this.setOptionsColor();
this.setOptionsData(); this.setOptionsData();
}, },
// //
@ -412,7 +383,7 @@ export default {
legend.itemWidth = optionsSetup.legendWidth; legend.itemWidth = optionsSetup.legendWidth;
}, },
// //
setOptionsLegendName(name){ setOptionsLegendName(name) {
const optionsSetup = this.optionsSetup; const optionsSetup = this.optionsSetup;
const series = this.options.series; const series = this.options.series;
const legendName = optionsSetup.legendName; const legendName = optionsSetup.legendName;
@ -422,7 +393,7 @@ export default {
series[i].name = name[i]; series[i].name = name[i];
} }
this.options.legend['data'] = name; this.options.legend['data'] = name;
}else { } else {
const arr = legendName.split('|'); const arr = legendName.split('|');
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
series[i].name = arr[i]; series[i].name = arr[i];
@ -430,24 +401,6 @@ export default {
this.options.legend['data'] = arr this.options.legend['data'] = arr
} }
}, },
//
setOptionsColor() {
const optionsSetup = this.optionsSetup;
const customColor = optionsSetup.customColor;
const series = this.options.series;
if (!customColor) return;
const arrColor = [];
for (let i = 0; i < customColor.length; i++) {
arrColor.push(customColor[i].color);
}
for (const i in series) {
if (series[i].type == 'bar') {
series[i].itemStyle.normal['color'] = arrColor[i];
} else {
series[i].lineStyle['color'] = arrColor[i];
}
}
},
// //
setOptionsData() { setOptionsData() {
const optionsData = this.optionsData; // or const optionsData = this.optionsData; // or
@ -457,6 +410,12 @@ export default {
}, },
staticDataFn(val) { staticDataFn(val) {
const optionsSetup = this.optionsSetup; const optionsSetup = this.optionsSetup;
//
const customColor = optionsSetup.customColor;
const arrColor = [];
for (let i = 0; i < customColor.length; i++) {
arrColor.push(customColor[i].color);
}
const series = this.options.series; const series = this.options.series;
let axis = []; let axis = [];
let bar1 = []; let bar1 = [];
@ -468,11 +427,17 @@ export default {
bar2[i] = val[i].manus; bar2[i] = val[i].manus;
line[i] = val[i].sales; line[i] = val[i].sales;
} }
const legendName = [];
legendName.push('调解成功');
legendName.push('调解失败');
legendName.push('调解成功率');
// x // x
this.options.xAxis.data = axis; this.options.xAxis.data = axis;
// series // series
for (const i in series) { for (const i in series) {
if (series[i].type == 'bar') { if (series[i].type == 'bar') {
series[i].name = legendName[i];
series[i].type = 'bar';
series[i].label = { series[i].label = {
show: optionsSetup.isShowBar, show: optionsSetup.isShowBar,
position: 'top', position: 'top',
@ -483,8 +448,12 @@ export default {
}; };
series[i].barWidth = optionsSetup.maxWidth; series[i].barWidth = optionsSetup.maxWidth;
series[i].itemStyle.normal['barBorderRadius'] = optionsSetup.radius; series[i].itemStyle.normal['barBorderRadius'] = optionsSetup.radius;
series[i].itemStyle.normal['color'] = arrColor[i];
} else if (series[i].type == 'line') { } else if (series[i].type == 'line') {
series[i].name = legendName[i];
series[i].type = 'line';
series[i].yAxisIndex = 1; series[i].yAxisIndex = 1;
series[i].symbol = optionsSetup.symbol;
series[i].showSymbol = optionsSetup.markPoint; series[i].showSymbol = optionsSetup.markPoint;
series[i].symbolSize = optionsSetup.pointSize; series[i].symbolSize = optionsSetup.pointSize;
series[i].smooth = optionsSetup.smoothCurve; series[i].smooth = optionsSetup.smoothCurve;
@ -497,7 +466,13 @@ export default {
opacity: 0 opacity: 0
}; };
} }
series[i].itemStyle = {
normal: {
color: arrColor[i],
}
};
series[i].lineStyle = { series[i].lineStyle = {
color: arrColor[i],
width: optionsSetup.lineWidth width: optionsSetup.lineWidth
}; };
series[i].label = { series[i].label = {
@ -512,11 +487,7 @@ export default {
} }
series[0].data = bar1; series[0].data = bar1;
series[1].data = bar2; series[1].data = bar2;
series[3].data = line; series[2].data = line;
const legendName = [];
legendName.push('调解成功');
legendName.push('调解失败');
legendName.push('调解成功率');
this.options.legend['data'] = legendName; this.options.legend['data'] = legendName;
this.setOptionsLegendName(legendName); this.setOptionsLegendName(legendName);
}, },
@ -539,10 +510,17 @@ export default {
}, },
renderingFn(val) { renderingFn(val) {
const optionsSetup = this.optionsSetup; const optionsSetup = this.optionsSetup;
//
const customColor = optionsSetup.customColor;
const arrColor = [];
for (let i = 0; i < customColor.length; i++) {
arrColor.push(customColor[i].color);
}
this.options.xAxis.data = val.xAxis; this.options.xAxis.data = val.xAxis;
const series = []; const series = [];
const legendName = []; const legendName = [];
for (const i in val.series) { for (const i in val.series) {
legendName.push(val.series[i].name);
const obj = {}; const obj = {};
if (val.series[i].type == 'bar') { if (val.series[i].type == 'bar') {
obj.name = val.series[i].name; obj.name = val.series[i].name;
@ -558,6 +536,7 @@ export default {
obj.barWidth = optionsSetup.maxWidth; obj.barWidth = optionsSetup.maxWidth;
obj.itemStyle = { obj.itemStyle = {
normal: { normal: {
color: arrColor[i],
barBorderRadius: optionsSetup.radius, barBorderRadius: optionsSetup.radius,
} }
}; };
@ -567,6 +546,7 @@ export default {
obj.name = val.series[i].name; obj.name = val.series[i].name;
obj.type = val.series[i].type; obj.type = val.series[i].type;
obj.yAxisIndex = 1; obj.yAxisIndex = 1;
obj.symbol = optionsSetup.symbol;
obj.showSymbol = optionsSetup.markPoint; obj.showSymbol = optionsSetup.markPoint;
obj.symbolSize = optionsSetup.pointSize; obj.symbolSize = optionsSetup.pointSize;
obj.smooth = optionsSetup.smoothCurve; obj.smooth = optionsSetup.smoothCurve;
@ -577,9 +557,15 @@ export default {
} else { } else {
obj.areaStyle = { obj.areaStyle = {
opacity: 0 opacity: 0
}; }
} }
obj.itemStyle = {
normal: {
color: arrColor[i],
}
};
obj.lineStyle = { obj.lineStyle = {
color: arrColor[i],
width: optionsSetup.lineWidth width: optionsSetup.lineWidth
}; };
obj.label = { obj.label = {
@ -593,7 +579,6 @@ export default {
obj.data = val.series[i].data; obj.data = val.series[i].data;
series.push(obj); series.push(obj);
} }
legendName.push(val.series[i].name);
} }
this.options.series = series; this.options.series = series;
this.options.legend['data'] = legendName; this.options.legend['data'] = legendName;

Loading…
Cancel
Save