yanzili 3 years ago
commit 36dd7d9555

@ -4853,7 +4853,7 @@ const widgetTools = [
label: '', label: '',
name: 'customColor', name: 'customColor',
required: false, required: false,
value: [{ color: '#ED0E0E' }, { color: '#6CCD17' }, { color: '#172CCD' }, { color: '#B817CD' }, { color: '#AFCD17' }], value: [{ color: '#FF801C' }, { color: '#F5FF46' }, { color: '#00FE65' }, { color: '#00FEFF' }, { color: '#ffa800' }]
}, },
], ],
}, },

@ -155,8 +155,8 @@ export default {
show: optionsCollapse.isShowSplitLineX, show: optionsCollapse.isShowSplitLineX,
lineStyle: { lineStyle: {
color: optionsCollapse.splitLineColorX color: optionsCollapse.splitLineColorX
}, }
}, }
}; };
this.options.xAxis = xAxis; this.options.xAxis = xAxis;
}, },
@ -192,8 +192,8 @@ export default {
show: optionsCollapse.isShowSplitLineY, show: optionsCollapse.isShowSplitLineY,
lineStyle: { lineStyle: {
color: optionsCollapse.splitLineColorY color: optionsCollapse.splitLineColorY
}, }
}, }
}; };
this.options.yAxis = yAxis; this.options.yAxis = yAxis;
@ -289,7 +289,6 @@ export default {
setOptionsData() { setOptionsData() {
const optionsSetup = this.optionsSetup; const optionsSetup = this.optionsSetup;
const optionsData = this.optionsData; // or const optionsData = this.optionsData; // or
console.log(optionsData);
optionsData.dataType == "staticData" optionsData.dataType == "staticData"
? this.staticDataFn(optionsData.staticData, optionsSetup) ? this.staticDataFn(optionsData.staticData, optionsSetup)
: this.dynamicDataFn( : this.dynamicDataFn(

@ -1,17 +1,16 @@
<template> <template>
<div :style="styleObj"> <div :style="styleObj">
<v-chart :options="options" <v-chart :options="options" autoresize />
autoresize />
</div> </div>
</template> </template>
<script> <script>
export default { export default {
name: 'WidgetLinechart', name: "WidgetLinechart",
components: {}, components: {},
props: { props: {
value: Object, value: Object,
ispreview: Boolean, ispreview: Boolean
}, },
data() { data() {
return { return {
@ -19,127 +18,127 @@ export default {
grid: {}, grid: {},
color: [], color: [],
title: { title: {
text: '', text: "",
textStyle: { textStyle: {
color: '#fff', color: "#fff"
}, }
}, },
tooltip: { tooltip: {
trigger: 'item', trigger: "item",
formatter: '{a} <br/>{b} : {c}%', formatter: "{a} <br/>{b} : {c}%"
}, },
legend: { legend: {
textStyle: { textStyle: {
color: '#fff', color: "#fff"
}, }
}, },
xAxis: { xAxis: {
type: 'category', type: "category",
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
axisLabel: { axisLabel: {
show: true, show: true,
textStyle: { textStyle: {
color: '#fff', color: "#fff"
}, }
}, }
}, },
yAxis: { yAxis: {
type: 'value', type: "value",
axisLabel: { axisLabel: {
show: true, show: true,
textStyle: { textStyle: {
color: '#fff', color: "#fff"
}, }
}, }
}, },
series: [ series: [
{ {
data: [], data: [],
type: 'line', type: "line"
}, }
], ]
}, },
optionsStyle: {}, // optionsStyle: {}, //
optionsData: {}, // optionsData: {}, //
optionsCollapse: {}, // optionsCollapse: {}, //
optionsSetup: {}, optionsSetup: {}
} };
}, },
computed: { computed: {
styleObj() { styleObj() {
return { return {
position: this.ispreview ? 'absolute' : 'static', position: this.ispreview ? "absolute" : "static",
width: this.optionsStyle.width + 'px', width: this.optionsStyle.width + "px",
height: this.optionsStyle.height + 'px', height: this.optionsStyle.height + "px",
left: this.optionsStyle.left + 'px', left: this.optionsStyle.left + "px",
top: this.optionsStyle.top + 'px', top: this.optionsStyle.top + "px",
background: this.optionsSetup.background, background: this.optionsSetup.background
};
} }
}, },
},
watch: { watch: {
value: { value: {
handler(val) { handler(val) {
this.optionsStyle = val.position this.optionsStyle = val.position;
this.optionsData = val.data this.optionsData = val.data;
this.optionsCollapse = val.collapse this.optionsCollapse = val.collapse;
this.optionsSetup = val.setup this.optionsSetup = val.setup;
this.editorOptions() this.editorOptions();
},
deep: true,
}, },
deep: true
}
}, },
created() { created() {
this.optionsStyle = this.value.position this.optionsStyle = this.value.position;
this.optionsData = this.value.data this.optionsData = this.value.data;
this.optionsCollapse = this.value.collapse this.optionsCollapse = this.value.collapse;
this.optionsSetup = this.value.setup this.optionsSetup = this.value.setup;
this.editorOptions() this.editorOptions();
}, },
methods: { methods: {
// options // options
editorOptions() { editorOptions() {
this.setOptionsTitle() this.setOptionsTitle();
this.setOptionsX() this.setOptionsX();
this.setOptionsY() this.setOptionsY();
this.setOptionsTop() this.setOptionsTop();
this.setOptionsTooltip() this.setOptionsTooltip();
this.setOptionsData() this.setOptionsData();
this.setOptionsMargin() this.setOptionsMargin();
this.setOptionsLegend() this.setOptionsLegend();
this.setOptionsColor() this.setOptionsColor();
}, },
// //
setOptionsTitle() { setOptionsTitle() {
const optionsCollapse = this.optionsSetup const optionsCollapse = this.optionsSetup;
const title = {} const title = {};
title.text = optionsCollapse.titleText title.text = optionsCollapse.titleText;
title.show = optionsCollapse.isNoTitle title.show = optionsCollapse.isNoTitle;
title.left = optionsCollapse.textAlign title.left = optionsCollapse.textAlign;
title.textStyle = { title.textStyle = {
color: optionsCollapse.textColor, color: optionsCollapse.textColor,
fontSize: optionsCollapse.textFontSize, fontSize: optionsCollapse.textFontSize,
fontWeight: optionsCollapse.textFontWeight, fontWeight: optionsCollapse.textFontWeight
} };
title.subtext = optionsCollapse.subText title.subtext = optionsCollapse.subText;
title.subtextStyle = { title.subtextStyle = {
color: optionsCollapse.subTextColor, color: optionsCollapse.subTextColor,
fontWeight: optionsCollapse.subTextFontWeight, fontWeight: optionsCollapse.subTextFontWeight,
fontSize: optionsCollapse.subTextFontSize, fontSize: optionsCollapse.subTextFontSize
} };
this.options.title = title this.options.title = title;
}, },
// X // X
setOptionsX() { setOptionsX() {
const optionsCollapse = this.optionsSetup const optionsCollapse = this.optionsSetup;
const xAxis = { const xAxis = {
type: 'category', type: "category",
show: optionsCollapse.hideX, // show: optionsCollapse.hideX, //
name: optionsCollapse.xName, // name: optionsCollapse.xName, //
nameTextStyle: { nameTextStyle: {
color: optionsCollapse.xNameColor, color: optionsCollapse.xNameColor,
fontSize: optionsCollapse.xNameFontSize, fontSize: optionsCollapse.xNameFontSize
}, },
nameRotate: optionsCollapse.textAngle, // nameRotate: optionsCollapse.textAngle, //
inverse: optionsCollapse.reversalX, // inverse: optionsCollapse.reversalX, //
@ -149,181 +148,184 @@ export default {
rotate: optionsCollapse.textAngle, // rotate: optionsCollapse.textAngle, //
textStyle: { textStyle: {
color: optionsCollapse.Xcolor, // x color: optionsCollapse.Xcolor, // x
fontSize: optionsCollapse.fontSizeX, fontSize: optionsCollapse.fontSizeX
}, }
}, },
axisLine: { axisLine: {
show: true, show: true,
lineStyle: { lineStyle: {
color: optionsCollapse.lineColorX, color: optionsCollapse.lineColorX
}, }
}, },
splitLine: { splitLine: {
show: optionsCollapse.isShowSplitLineX, show: optionsCollapse.isShowSplitLineX,
lineStyle: { lineStyle: {
color: optionsCollapse.splitLineColorX color: optionsCollapse.splitLineColorX
},
},
} }
this.options.xAxis = xAxis }
};
this.options.xAxis = xAxis;
}, },
// Y // Y
setOptionsY() { setOptionsY() {
const optionsCollapse = this.optionsSetup const optionsCollapse = this.optionsSetup;
const yAxis = { const yAxis = {
type: 'value', type: "value",
show: optionsCollapse.isShowY, // show: optionsCollapse.isShowY, //
name: optionsCollapse.textNameY, // name: optionsCollapse.textNameY, //
nameTextStyle: { nameTextStyle: {
color: optionsCollapse.NameColorY, color: optionsCollapse.NameColorY,
fontSize: optionsCollapse.NameFontSizeY, fontSize: optionsCollapse.NameFontSizeY
}, },
inverse: optionsCollapse.reversalY, // inverse: optionsCollapse.reversalY, //
axisLabel: { axisLabel: {
show: true, show: true,
textStyle: { textStyle: {
color: optionsCollapse.colorY, // x color: optionsCollapse.colorY, // x
fontSize: optionsCollapse.fontSizeY, fontSize: optionsCollapse.fontSizeY
}, }
}, },
splitLine: { splitLine: {
show: false, show: false
}, },
axisLine: { axisLine: {
show: true, show: true,
lineStyle: { lineStyle: {
color: optionsCollapse.lineColorY, color: optionsCollapse.lineColorY
}, }
}, },
splitLine: { splitLine: {
show: optionsCollapse.isShowSplitLineY, show: optionsCollapse.isShowSplitLineY,
lineStyle: { lineStyle: {
color: optionsCollapse.splitLineColorY color: optionsCollapse.splitLineColorY
},
},
} }
}
};
this.options.yAxis = yAxis this.options.yAxis = yAxis;
}, },
// 线 // 线
setOptionsTop() { setOptionsTop() {
const optionsCollapse = this.optionsSetup const optionsCollapse = this.optionsSetup;
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].showSymbol = optionsCollapse.markPoint series[key].showSymbol = optionsCollapse.markPoint;
series[key].symbolSize = optionsCollapse.pointSize series[key].symbolSize = optionsCollapse.pointSize;
series[key].smooth = optionsCollapse.smoothCurve series[key].smooth = optionsCollapse.smoothCurve;
if (optionsCollapse.area) { if (optionsCollapse.area) {
series[key].areaStyle = { series[key].areaStyle = {
opacity: optionsCollapse.areaThickness / 100, opacity: optionsCollapse.areaThickness / 100
} };
} else { } else {
series[key].areaStyle = { series[key].areaStyle = {
opacity: 0, opacity: 0
} };
} }
series[key].lineStyle = { series[key].lineStyle = {
width: optionsCollapse.lineWidth, width: optionsCollapse.lineWidth
} };
series[key].label = { series[key].label = {
show: optionsCollapse.isShow, show: optionsCollapse.isShow,
position: 'top', position: "top",
distance: 10, distance: 10,
fontSize: optionsCollapse.fontSize, fontSize: optionsCollapse.fontSize,
color: optionsCollapse.subTextColor, color: optionsCollapse.subTextColor,
fontWeight: optionsCollapse.fontWeight, fontWeight: optionsCollapse.fontWeight
} };
} }
} }
this.options.series = series this.options.series = series;
}, },
// tooltip // tooltip
setOptionsTooltip() { setOptionsTooltip() {
const optionsCollapse = this.optionsSetup const optionsCollapse = this.optionsSetup;
const tooltip = { const tooltip = {
trigger: 'item', trigger: "item",
show: true, show: true,
textStyle: { textStyle: {
color: optionsCollapse.lineColor, color: optionsCollapse.lineColor,
fontSize: optionsCollapse.fontSize, fontSize: optionsCollapse.fontSize
},
} }
this.options.tooltip = tooltip };
this.options.tooltip = tooltip;
}, },
// //
setOptionsMargin() { setOptionsMargin() {
const optionsCollapse = this.optionsSetup const optionsCollapse = this.optionsSetup;
const grid = { const grid = {
left: optionsCollapse.marginLeft, left: optionsCollapse.marginLeft,
right: optionsCollapse.marginRight, right: optionsCollapse.marginRight,
bottom: optionsCollapse.marginBottom, bottom: optionsCollapse.marginBottom,
top: optionsCollapse.marginTop, top: optionsCollapse.marginTop,
containLabel: true, containLabel: true
} };
this.options.grid = grid this.options.grid = grid;
}, },
// legend // legend
setOptionsLegend() { setOptionsLegend() {
const optionsCollapse = this.optionsSetup const optionsCollapse = this.optionsSetup;
const legend = this.options.legend const legend = this.options.legend;
legend.show = optionsCollapse.isShowLegend legend.show = optionsCollapse.isShowLegend;
legend.left = optionsCollapse.lateralPosition == 'left' ? 0 : 'auto' legend.left = optionsCollapse.lateralPosition == "left" ? 0 : "auto";
legend.right = optionsCollapse.lateralPosition == 'right' ? 0 : 'auto' legend.right = optionsCollapse.lateralPosition == "right" ? 0 : "auto";
legend.top = optionsCollapse.longitudinalPosition == 'top' ? 0 : 'auto' legend.top = optionsCollapse.longitudinalPosition == "top" ? 0 : "auto";
legend.bottom = optionsCollapse.longitudinalPosition == 'bottom' ? 0 : 'auto' legend.bottom =
legend.orient = optionsCollapse.layoutFront optionsCollapse.longitudinalPosition == "bottom" ? 0 : "auto";
legend.orient = optionsCollapse.layoutFront;
legend.textStyle = { legend.textStyle = {
color: optionsCollapse.lengedColor, color: optionsCollapse.lengedColor,
fontSize: optionsCollapse.fontSize, fontSize: optionsCollapse.fontSize
} };
legend.itemWidth = optionsCollapse.lengedWidth legend.itemWidth = optionsCollapse.lengedWidth;
console.log(legend) console.log(legend);
}, },
// //
setOptionsColor() { setOptionsColor() {
const optionsCollapse = this.optionsSetup const optionsCollapse = this.optionsSetup;
const customColor = optionsCollapse.customColor const customColor = optionsCollapse.customColor;
if (!customColor) return if (!customColor) return;
const arrColor = [] const arrColor = [];
for (let i = 0; i < customColor.length; i++) { for (let i = 0; i < customColor.length; i++) {
arrColor.push(customColor[i].color) arrColor.push(customColor[i].color);
} }
this.options.color = arrColor this.options.color = arrColor;
this.options = Object.assign({}, this.options) this.options = Object.assign({}, this.options);
}, },
// //
setOptionsData() { setOptionsData() {
const optionsData = this.optionsData // or const optionsData = this.optionsData; // or
optionsData.dataType == 'staticData' ? this.staticDataFn(optionsData.staticData) : this.dynamicDataFn(optionsData.dynamicData) optionsData.dataType == "staticData"
? this.staticDataFn(optionsData.staticData)
: this.dynamicDataFn(optionsData.dynamicData);
}, },
staticDataFn(val) { staticDataFn(val) {
const staticData = JSON.parse(val) const staticData = JSON.parse(val);
// x // x
this.options.xAxis.data = staticData.categories this.options.xAxis.data = staticData.categories;
// series // series
const series = this.options.series const series = this.options.series;
for (const i in series) { for (const i in series) {
if (series[i].type == 'line') { if (series[i].type == "line") {
series[i].data = staticData.series[0].data series[i].data = staticData.series[0].data;
} }
} }
}, },
dynamicDataFn(val) { dynamicDataFn(val) {
if (!val) return if (!val) return;
// x // x
this.options.xAxis.data = val.xAxis this.options.xAxis.data = val.xAxis;
// series // series
const series = this.options.series const series = this.options.series;
for (const i in series) { for (const i in series) {
if (series[i].type == 'line') { if (series[i].type == "line") {
series[i].data = val.series[i].data series[i].data = val.series[i].data;
}
} }
} }
},
},
} }
};
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

Loading…
Cancel
Save