feat--柱状图支持多柱

qianming 1 year ago
parent fd871c031b
commit 22c5b17484

@ -67,6 +67,18 @@ export const widgetBarchart = {
placeholder: '',
value: 0,
},
{
type: 'el-select',
label: '堆叠样式',
name: 'stackStyle',
required: false,
placeholder: '',
selectOptions: [
{ code: 'leftRight', name: '左右堆叠' },
{ code: 'upDown', name: '上下堆叠' },
],
value: 'leftRight'
},
],
},
{
@ -197,6 +209,88 @@ export const widgetBarchart = {
},
],
},
{
name: '图例操作',
list: [
{
type: 'el-switch',
label: '图例显示',
name: 'isShowLegend',
required: false,
placeholder: '',
value: true,
},
{
type: 'el-input-text',
label: '名称( | 分隔)',
name: 'legendName',
required: false,
placeholder: '多值以' | '隔开',
value: ''
},
{
type: 'vue-color',
label: '字体颜色',
name: 'legendColor',
required: false,
placeholder: '',
value: '#fff',
},
{
type: 'el-input-number',
label: '字体字号',
name: 'legendFontSize',
required: false,
placeholder: '',
value: 12,
},
{
type: 'el-input-number',
label: '图例宽度',
name: 'legendWidth',
required: false,
placeholder: '',
value: 12,
},
{
type: 'el-select',
label: '横向位置',
name: 'lateralPosition',
required: false,
placeholder: '',
selectOptions: [
{ code: 'center', name: '居中' },
{ code: 'left', name: '左对齐' },
{ code: 'right', name: '右对齐' },
],
value: 'center'
},
{
type: 'el-select',
label: '纵向位置',
name: 'longitudinalPosition',
required: false,
placeholder: '',
selectOptions: [
{ code: 'top', name: '顶部' },
{ code: 'bottom', name: '底部' },
],
value: 'top'
},
{
type: 'el-select',
label: '布局前置',
name: 'layoutFront',
required: false,
placeholder: '',
selectOptions: [
{ code: 'vertical', name: '竖排' },
{ code: 'horizontal', name: '横排' },
],
value: 'horizontal'
},
],
},
{
name: 'X轴设置',
list: [
@ -548,6 +642,18 @@ export const widgetBarchart = {
{
name: '自定义配色',
list: [
{
type: 'el-select',
label: '配色样式',
name: 'colorStyle',
required: false,
placeholder: '',
selectOptions: [
{ code: 'same', name: '同色' },
{ code: 'unsame', name: '异色' },
],
value: 'same'
},
{
type: 'customColor',
label: '',

@ -1,6 +1,6 @@
<template>
<div :style="styleObj">
<v-chart ref="myVChart" :options="options" autoresize />
<v-chart ref="myVChart" :options="options" autoresize/>
</div>
</template>
@ -9,6 +9,7 @@ import {
originWidgetLinkageLogic,
targetWidgetLinkageLogic,
} from "@/views/bigscreenDesigner/designer/linkageLogic";
export default {
name: "WidgetBarchart",
components: {},
@ -108,10 +109,9 @@ export default {
this.setOptionsTitle();
this.setOptionsX();
this.setOptionsY();
this.setOptionsTop();
this.setOptionsLegend();
this.setOptionsTooltip();
this.setOptionsMargin();
this.setOptionsColor();
this.setOptionsData();
},
//
@ -225,36 +225,6 @@ export default {
};
this.options.yAxis = yAxis;
},
// or
setOptionsTop() {
const optionsSetup = this.optionsSetup;
const series = this.options.series;
if (series[0].type == "bar") {
if (optionsSetup.verticalShow) {
series[0].label = {
show: optionsSetup.isShow,
position: "right",
distance: optionsSetup.distance,
textStyle: {
fontSize: optionsSetup.fontSize,
color: optionsSetup.dataColor,
fontWeight: optionsSetup.fontWeight,
},
};
} else {
series[0].label = {
show: optionsSetup.isShow,
position: "top",
distance: optionsSetup.distance,
fontSize: optionsSetup.fontSize,
color: optionsSetup.dataColor,
fontWeight: optionsSetup.fontWeight,
};
}
}
series[0].barWidth = optionsSetup.maxWidth;
series[0].barMinHeight = optionsSetup.minHeight;
},
// tooltip
setOptionsTooltip() {
const optionsSetup = this.optionsSetup;
@ -280,33 +250,62 @@ export default {
};
this.options.grid = grid;
},
//
setOptionsColor() {
//
setOptionsLegend() {
const optionsSetup = this.optionsSetup;
const customColor = optionsSetup.customColor;
if (!customColor) return;
const arrColor = [];
for (let i = 0; i < customColor.length; i++) {
arrColor.push(customColor[i].color);
}
const itemStyle = {
normal: {
color: (params) => {
return arrColor[params.dataIndex];
const legend = this.options.legend;
legend.show = optionsSetup.isShowLegend;
legend.left = optionsSetup.lateralPosition;
legend.top = optionsSetup.longitudinalPosition;
legend.bottom = optionsSetup.longitudinalPosition;
legend.orient = optionsSetup.layoutFront;
legend.textStyle = {
color: optionsSetup.legendColor,
fontSize: optionsSetup.legendFontSize,
};
legend.itemWidth = optionsSetup.legendWidth;
},
barBorderRadius: optionsSetup.radius,
//
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;
}
},
};
for (const key in this.options.series) {
if (this.options.series[key].type == "bar") {
this.options.series[key].itemStyle = itemStyle;
//
getStackStyle() {
const optionsSetup = this.optionsSetup;
let style = "";
if (optionsSetup.stackStyle == "upDown") {
style = "total";
}
return style;
},
//
getOptionsPosition() {
const optionsSetup = this.optionsSetup;
let position = "";
if (optionsSetup.verticalShow) {
position = "right";
} else {
position = "top";
}
this.options = Object.assign({}, this.options);
return position;
},
//
setOptionsData(e, paramsConfig) {
const optionsSetup = this.optionsSetup;
const optionsData = this.optionsData; // or
//
optionsData.dynamicData = optionsData.dynamicData || {}; // dynamicData undefined
@ -332,6 +331,12 @@ export default {
//
staticDataFn(val) {
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;
let axis = [];
let data = [];
@ -339,6 +344,8 @@ export default {
axis[i] = val[i].axis;
data[i] = val[i].data;
}
const legendName = [];
legendName.push("bar");
// x
if (optionsSetup.verticalShow) {
this.options.xAxis.data = [];
@ -351,8 +358,42 @@ export default {
this.options.xAxis.type = "category";
this.options.yAxis.type = "value";
}
if (series[0].type == "bar") {
series[0].data = data;
for (const i in series) {
if (series[i].type == "bar") {
series[i].type = "bar";
series[i].barGap = "0%";
series[i].barWidth = optionsSetup.maxWidth;
series[i].barMinHeight = optionsSetup.minHeight;
series[i].label = {
show: optionsSetup.isShow,
position: this.getOptionsPosition(),
distance: optionsSetup.distance,
fontSize: optionsSetup.fontSize,
color: optionsSetup.dataColor,
fontWeight: optionsSetup.fontWeight,
};
//
if (optionsSetup.colorStyle == 'same') {
series[i].itemStyle = {
normal: {
color: arrColor[i],
barBorderRadius: optionsSetup.radius,
},
};
} else {
series[i].itemStyle = {
normal: {
color: (params) => {
return arrColor[params.dataIndex];
},
barBorderRadius: optionsSetup.radius,
},
};
}
series[i].data = data;
this.options.legend["data"] = legendName;
this.setOptionsLegendName(legendName);
}
}
},
//
@ -377,6 +418,14 @@ export default {
});
},
renderingFn(optionsSetup, val) {
//
const customColor = optionsSetup.customColor;
const arrColor = [];
for (let i = 0; i < customColor.length; i++) {
arrColor.push(customColor[i].color);
}
const series = [];
const legendName = [];
// x
if (optionsSetup.verticalShow) {
this.options.xAxis.data = [];
@ -389,13 +438,48 @@ export default {
this.options.xAxis.type = "category";
this.options.yAxis.type = "value";
}
// series
const series = this.options.series;
for (const i in series) {
if (series[i].type == "bar") {
series[i].data = val.series[i].data;
for (const i in val.series) {
legendName.push(val.series[i].name);
const obj = {};
if (val.series[i].type == "bar") {
obj.type = "bar";
obj.barGap = "0%";
obj.stack = this.getStackStyle();
obj.barWidth = optionsSetup.maxWidth;
obj.barMinHeight = optionsSetup.minHeight;
obj.label = {
show: optionsSetup.isShow,
position: this.getOptionsPosition(),
distance: optionsSetup.distance,
fontSize: optionsSetup.fontSize,
color: optionsSetup.dataColor,
fontWeight: optionsSetup.fontWeight,
};
//
if (optionsSetup.colorStyle == 'same') {
obj.itemStyle = {
normal: {
color: arrColor[i],
barBorderRadius: optionsSetup.radius,
},
};
} else {
obj.itemStyle = {
normal: {
color: (params) => {
return arrColor[params.dataIndex];
},
barBorderRadius: optionsSetup.radius,
},
};
}
obj.data = val.series[i].data;
series.push(obj);
}
}
this.options.series = series;
this.options.legend["data"] = legendName;
this.setOptionsLegendName(legendName);
},
},
};

@ -293,9 +293,6 @@ export default {
},
//
setOptionsData(e, paramsConfig) {
console.log("ces", e);
console.log("ces", paramsConfig);
const optionsData = this.optionsData; // or
optionsData.dynamicData = optionsData.dynamicData || {}; // dynamicData undefined
const myDynamicData = optionsData.dynamicData;
@ -312,7 +309,6 @@ export default {
}
});
}
console.log(myDynamicData);
optionsData.dataType == "staticData"
? this.staticDataFn(optionsData.staticData)
: this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);

Loading…
Cancel
Save