|
@@ -3,6 +3,11 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+let colors = [
|
|
|
+ "RGBA(235, 184, 86, 1)",
|
|
|
+ "RGBA(100, 184, 255, 1)",
|
|
|
+ "RGBA(71, 203, 129, 1)",
|
|
|
+];
|
|
|
let option = {
|
|
|
legend: {
|
|
|
tooltip: {
|
|
@@ -85,33 +90,34 @@ let option = {
|
|
|
export default {
|
|
|
name: "pie_echart",
|
|
|
components: {},
|
|
|
+ props: {
|
|
|
+ unit: {
|
|
|
+ type: String,
|
|
|
+ },
|
|
|
+ },
|
|
|
data() {
|
|
|
return {
|
|
|
myChart: null,
|
|
|
};
|
|
|
},
|
|
|
methods: {
|
|
|
- setOptions(legend, data) {
|
|
|
+ setOptions(data) {
|
|
|
if (!this.myChart) {
|
|
|
// var dom = document.getElementById("pie_echart");
|
|
|
this.myChart = echarts.init(this.$refs.echart);
|
|
|
}
|
|
|
- this.initEchartXzqh(legend, data);
|
|
|
+ this.initEchartXzqh(data);
|
|
|
},
|
|
|
- initEchartXzqh(legend, optionsData) {
|
|
|
- option.legend.data = legend;
|
|
|
+ initEchartXzqh(optionsData) {
|
|
|
+ let _this = this;
|
|
|
option.legend.formatter = function (name) {
|
|
|
const sItem = optionsData.find((item) =>
|
|
|
`${item.name}`.includes(`${name}`)
|
|
|
);
|
|
|
if (sItem) {
|
|
|
- console.log(sItem, "sItem");
|
|
|
-
|
|
|
- return `{name|${name}} {value|${sItem.value}} {unit|km²} `;
|
|
|
+ return `{name|${name}} {value|${sItem.value}} {unit|${_this.$props.unit}} `;
|
|
|
// return name + 'sItem.value';
|
|
|
} else {
|
|
|
- console.log(name);
|
|
|
-
|
|
|
return name;
|
|
|
}
|
|
|
};
|
|
@@ -304,18 +310,7 @@ export default {
|
|
|
},
|
|
|
};
|
|
|
|
|
|
- if (typeof pieData[i].itemStyle != "undefined") {
|
|
|
- let itemStyle = {};
|
|
|
-
|
|
|
- typeof pieData[i].itemStyle.color != "undefined"
|
|
|
- ? (itemStyle.color = pieData[i].itemStyle.color)
|
|
|
- : null;
|
|
|
- typeof pieData[i].itemStyle.opacity != "undefined"
|
|
|
- ? (itemStyle.opacity = pieData[i].itemStyle.opacity)
|
|
|
- : null;
|
|
|
-
|
|
|
- seriesItem.itemStyle = itemStyle;
|
|
|
- }
|
|
|
+ seriesItem.itemStyle = { color: colors[i], opacity: 0.8 };
|
|
|
|
|
|
series.push(seriesItem);
|
|
|
}
|
|
@@ -340,13 +335,11 @@ export default {
|
|
|
|
|
|
legendData.push(series[i].name);
|
|
|
}
|
|
|
-
|
|
|
+ option.legend.data = legendData;
|
|
|
return series;
|
|
|
},
|
|
|
},
|
|
|
- mounted() {
|
|
|
- this.setOptions();
|
|
|
- },
|
|
|
+ mounted() {},
|
|
|
};
|
|
|
</script>
|
|
|
<style lang="scss" scoped>
|