|
@@ -37,19 +37,36 @@ let option = {
|
|
y: "45%",
|
|
y: "45%",
|
|
},
|
|
},
|
|
legend: {
|
|
legend: {
|
|
|
|
+ type: "scroll",
|
|
orient: "vertical",
|
|
orient: "vertical",
|
|
- right: "10%",
|
|
|
|
|
|
+ right: "5%",
|
|
top: "center",
|
|
top: "center",
|
|
data: [],
|
|
data: [],
|
|
icon: "rect", // 这个字段控制形状 类型包括 circle,rect ,roundRect,triangle,diamond,pin,arrow,none
|
|
icon: "rect", // 这个字段控制形状 类型包括 circle,rect ,roundRect,triangle,diamond,pin,arrow,none
|
|
- itemWidth: 10, // 设置宽度
|
|
|
|
- itemHeight: 10, // 设置高度
|
|
|
|
|
|
+ itemWidth: 12, // 设置宽度
|
|
|
|
+ itemHeight: 12, // 设置高度
|
|
|
|
|
|
itemGap: 10, // 设置间距
|
|
itemGap: 10, // 设置间距
|
|
textStyle: {
|
|
textStyle: {
|
|
//图例文字的样式
|
|
//图例文字的样式
|
|
color: "#fff",
|
|
color: "#fff",
|
|
- fontSize: 16,
|
|
|
|
|
|
+ fontSize: 14,
|
|
|
|
+ },
|
|
|
|
+ textStyle: {
|
|
|
|
+ rich: {
|
|
|
|
+ name: {
|
|
|
|
+ color: "#fff", //#BCD3E5
|
|
|
|
+ fontSize: 14,
|
|
|
|
+ },
|
|
|
|
+ value: {
|
|
|
|
+ color: "#64DAFF",
|
|
|
|
+ fontSize: 14,
|
|
|
|
+ },
|
|
|
|
+ unit: {
|
|
|
|
+ color: "#fff", //#BCD3E5
|
|
|
|
+ fontSize: 14,
|
|
|
|
+ },
|
|
|
|
+ },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
graphic: [
|
|
graphic: [
|
|
@@ -130,6 +147,12 @@ let option = {
|
|
};
|
|
};
|
|
export default {
|
|
export default {
|
|
name: "pie_echart",
|
|
name: "pie_echart",
|
|
|
|
+ props: {
|
|
|
|
+ unit: {
|
|
|
|
+ type: String,
|
|
|
|
+ default: "km²", //"平方千米",
|
|
|
|
+ },
|
|
|
|
+ },
|
|
components: {},
|
|
components: {},
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
@@ -138,6 +161,7 @@ export default {
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
setOptions(dataList) {
|
|
setOptions(dataList) {
|
|
|
|
+ let _this = this;
|
|
if (!this.myChart) {
|
|
if (!this.myChart) {
|
|
// var dom = document.getElementById("pie_echart");
|
|
// var dom = document.getElementById("pie_echart");
|
|
this.myChart = echarts.init(this.$refs.echart);
|
|
this.myChart = echarts.init(this.$refs.echart);
|
|
@@ -149,17 +173,30 @@ export default {
|
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
{
|
|
{
|
|
offset: 0,
|
|
offset: 0,
|
|
- color: colors[index][0],
|
|
|
|
|
|
+ color: colors[index % colors.length][0],
|
|
},
|
|
},
|
|
{
|
|
{
|
|
offset: 1,
|
|
offset: 1,
|
|
- color: colors[index][1],
|
|
|
|
|
|
+ color: colors[index % colors.length][1],
|
|
},
|
|
},
|
|
]),
|
|
]),
|
|
};
|
|
};
|
|
// dataAll += item.value;
|
|
// dataAll += item.value;
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ option.legend.formatter = function (name) {
|
|
|
|
+ const sItem = dataList.find((item) =>
|
|
|
|
+ `${item.name}`.includes(`${name}`)
|
|
|
|
+ );
|
|
|
|
+ if (sItem) {
|
|
|
|
+ let aname = name.length > 4 ? name.substr(0, 4) + "..." : name;
|
|
|
|
+ return `{name|${aname}} {value|${sItem.value}} {unit|${_this.$props.unit}} `;
|
|
|
|
+ // return name + 'sItem.value';
|
|
|
|
+ } else {
|
|
|
|
+ return name;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
option.series[0].data = dataList;
|
|
option.series[0].data = dataList;
|
|
this.myChart.resize();
|
|
this.myChart.resize();
|
|
this.myChart.setOption(option);
|
|
this.myChart.setOption(option);
|