给代码加一个let data = [ { "column1": "机组类型;风电、光伏、分布式", "column2": "Sum_装机容量;单位:万千瓦" }, { "column1": "风电", "column2": "1100.0" }, { "column1": "光伏", "column2": "540.0" }, { "column1": "煤电", "column2": "83700.0" }, { "column1": "燃气", "column2": "34260.0" } ]; data.forEach(item => { item.column2 = parseFloat(item.column2); }); let total = data.reduce((prev, curr) => prev + curr.column2, 0); // data.forEach(item => { // item.percent = (item.column2 / total * 100).toFixed(2) + '%'; // }); // 指定图表的配置项和数据 var option = { title: { text: '', left: 'center' }, tooltip: { trigger: 'item', formatter: '{b}: {c}兆瓦 ', }, // legend: { // orient: 'vertical', // left: 'left', // // data: data.map(item => item.column1) // }, series: [ { name: '比例', type: 'pie', radius: ['50%', '70%'], avoidLabelOverlap: false, label: { show: false, position: 'center' }, labelLine: { show: false }, data: data.map(item => { return { name: item.column1, value: item.column2, label: { show: true, position: 'outside', formatter: '{c|{c}兆瓦}\n{b|{b}} ', rich: { b: { color: '#000', align: "['500','250']", fontSize: 12, lineHeight: 40, // height: 24 }, c: { color: "#000", fontSize: 16, // lineHeight: 20, lineHeight: 10, align: "['500','250']", } }, labelLine: { show: true }, } }; }) } ] };连接线
时间: 2024-02-10 19:13:07 浏览: 59
js代码-两数之和 输入:nums = [2,7,11,15], target = 9 输出:[0,1]
好的,这是您的代码,我已经添加了您提供的数据,同时对代码进行了一些微调,使其更加美观易读:
```
let data = [
{
"column1": "机组类型;风电、光伏、分布式",
"column2": "Sum_装机容量;单位:万千瓦"
},
{
"column1": "风电",
"column2": "1100.0"
},
{
"column1": "光伏",
"column2": "540.0"
},
{
"column1": "煤电",
"column2": "83700.0"
},
{
"column1": "燃气",
"column2": "34260.0"
}
];
data.forEach(item => {
item.column2 = parseFloat(item.column2);
});
let total = data.reduce((prev, curr) => prev + curr.column2, 0);
var option = {
title: {
text: '',
left: 'center'
},
tooltip: {
trigger: 'item',
formatter: '{b}: {c}兆瓦',
},
series: [
{
name: '比例',
type: 'pie',
radius: ['50%', '70%'],
avoidLabelOverlap: false,
label: {
show: false,
position: 'center'
},
labelLine: {
show: false
},
data: data.map(item => {
return {
name: item.column1,
value: item.column2,
label: {
show: true,
position: 'outside',
formatter: '{c|{c}兆瓦}\n{b|{b}}',
rich: {
b: {
color: '#000',
align: 'center',
fontSize: 12,
lineHeight: 24
},
c: {
color: '#000',
align: 'center',
fontSize: 16,
lineHeight: 10
}
}
},
labelLine: {
show: true
}
};
})
}
]
};
```
希望这能够帮到您!
阅读全文