配置项如下
let color = ['#FF8700', '#ffc300', '#00e473', '#009DFF'];
let nameList = [2016, 2017, 2018, 2019, 2020];
let valueList = [51.77, 62.33, 66.28, 73.43, 79.15];
let colorList = [
{
type: 'linear',
// 两端添加透明度,模拟两端线收缩
colorStops: [
{
offset: 0,
color: '#008AFF', // 0% 处的颜色
},
{
offset: 1,
color: '#21F7FF',
},
],
},
{
type: 'linear',
// 两端添加透明度,模拟两端线收缩
colorStops: [
{
offset: 0,
color: '#06CA70', // 0% 处的颜色
},
{
offset: 1,
color: '#43F2B6',
},
],
},
{
type: 'linear',
// 两端添加透明度,模拟两端线收缩
colorStops: [
{
offset: 0,
color: '#867DFF', // 0% 处的颜色
},
{
offset: 1,
color: '#A59EFF',
},
],
},
{
type: 'linear',
// 两端添加透明度,模拟两端线收缩
colorStops: [
{
offset: 0,
color: '#4186FF', // 0% 处的颜色
},
{
offset: 1,
color: '#7BB2FF',
},
],
},
{
type: 'linear',
// 两端添加透明度,模拟两端线收缩
colorStops: [
{
offset: 0,
color: '#FFA531', // 0% 处的颜色
},
{
offset: 1,
color: '#FFC949',
},
],
},
];
// let chartData = [{
// name: "2020年",
// value: 13211,
// },
// {
// name: "2019年",
// value: 42111,
// },
// {
// name: "2018年",
// value: 81711,
// },
// {
// name: "2017年",
// value: 121711,
// },
// {
// name: "2016年",
// value: 121711,
// }
// ];
let chartData = [];
nameList.map((item, idx) => {
chartData.push({
name: item + '年',
value: valueList[idx],
});
});
let arrName = [];
let arrValue = [];
let sum = 0;
let pieSeries = [],
lineYAxis = [];
// 数据处理
chartData.forEach((v, i) => {
arrName.push(v.name);
arrValue.push(v.value);
sum = sum + v.value;
});
function getRadius(i) {
return [67 - i * 12 + '%', 59 - i * 12 + '%'];
}
// 图表option整理
chartData.forEach((v, i) => {
pieSeries.push({
name: '生均占地面积(平方米)',
type: 'pie',
clockWise: true,
hoverAnimation: false,
radius: getRadius(i),
center: ['50%', '50%'],
itemStyle: {
color: colorList[i],
},
label: {
show: false,
},
data: [
{
value: v.value,
name: v.name,
},
{
value: sum - v.value,
name: 'no',
itemStyle: {
color: 'rgba(0,0,0,0)',
},
},
],
});
// pieSeries.push({
// name: '',
// type: 'pie',
// silent: true,
// z: 1,
// clockWise: true, //顺时加载
// hoverAnimation: false, //鼠标移入变大
// radius: getRadius(i),
// center: ["50%", "50%"],
// label: {
// show: false
// },
// data: [{
// value: 7.5,
// itemStyle: {
// color: "#E3F0FF"
// }
// }, {
// value: 2.5,
// name: '',
// itemStyle: {
// color: "rgba(0,0,0,0)"
// }
// }]
// });
v.percent = ((v.value / sum) * 100).toFixed(2);
lineYAxis.push({
value: i,
textStyle: {
rich: {
circle: {
color: color[i],
padding: [0, 5],
},
},
},
});
});
console.log('pieSeries', pieSeries);
option = {
tooltip: {
backgroundColor: 'transparent',
borderWidth: 0,
trigger: 'item',
formatter: (item) => {
console.log(item);
if (item['name'] == 'no') {
return;
} else {
return `<div style='width:289px;height:107px;background:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASEAAABrCAMAAAAPd8SXAAADAFBMVEUAAAADTv9MqP1Np/8FZ/9Op/sCWP8MX/8IYP8IZP8MYf8NX/8CZP8KYv8KZP8KZf8IZf8AWf8IZ/9Lpvt67f8Obf8NbP9Mp/wzjPwegv84k/1Mp/0LcP8ojv9Lof9LpfoScv8kfv926v8fgf80kf0jff9WxP82kv4vi/0qjf83kP09mf1Ir/9Jpft71P9IpfxHof9Env9Jpfw4k/tLpfxDmP89l/1u4P82lv0ulP0qiv8dfP8ogv9EoPw/m/47lf0pgv9m1/9hyf0wkf01k/0/m/4mgf9NqPt05v9t3f9Iov0slv4vl/5Lp/xCnPxPrP06mP5Mpf1FoP1MqP1r1v9Np/xNp/tNqPxp2v9l0P9fyf9ayf9n0P8umP5z5P9v3v5Nqv1KpPx77f9hzP9Hovx67v9av/5Vtv5OqPwtmP4BC0ABDUQBEUcBG1EBMWgBFksBKV8BIlgBRn4BUYoBO3MBElABXpgBD0kBDkcBEU4BEEsC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zDEbqYSFsBAPu4s8Io5z53TBNr3nZss1gK1jKvc9hC6xBfIFgbp8w4G/fgQNkxN8fbMTfn4cOwYS/k3TAX+smsA5soWDq4ddouSVw3549e9o+/VThexnMzy1msro95ZAPTcR34CP2+2x04mccfogPZI8g9zY2njhxAv5Qx48f/1SsDWyHlX2JcEtwa4h14JtvNqFWGPC382RDC2g4CTP+APxGQwvuKhgnCUMlv0IwZXIHqiN0qNgkRy7S7GdqnIbm79HnPzHc8j0hAKZ73gruQ5dZdw1zv+AOAkeNUo+QSaO3M4+Be6l7BO5qXhrj7j4i0h+mDUrhqC+9l9OZ46rI7AHBwcF+MCV2ELqkG2Da7J2CG++8kZLPqmUeoG4SPM54WBUd7REeNdjL11lWCEd9BTicYZ4SSnf7Apj07ONz5d3oKgXXwo27i7makc86hht3i9hQgZOXhLe3txcXfFswHBjg4wCTc23C2eQUDDjeAc8twNH8bBx/f8qFuphyAwMFVxIWxmUPBDAp2wUH2LOJ2OwsA5UjVp555iybgpNpeSOMhJUAjpBHslCsFKbioAgzFIb1D8XJ9VCH5JH0UQ/k8LzDWTaFnmVAz1KB83dMB2DgaH0hlWRLYSseiwUTspmG9dOp6sJAddbnAtqHBbKTLUQbsX0EkXAnIekZKiyUJJZEfzZxfqRLv/4jI26TepAboMLWthBtxDcSRhJX4qFYK4bHIvoxgaOHjA680HQKhuiYEGC3xzydLW4E2LFFLBMPxVk6eoYcGgJ1aJ5eEkh0gpGsElI68go2iNrRReZnO/FA9nronCQSz8QPwWK6efqV4tFXdrqDzPcSUD5LjeWy7FwO80j62PMG4o1kkeShsJUCWoaTnsTXS/aPiLWDHbEVukAZLSOO04u2j9XzLzEU5wy5rBIdCdprT0/locSpeCx1vfhoWZVQJJYa7PKv0/wDOJOoJaoEef4AAAAASUVORK5CYII=") no-repeat center center'>
<div style='color:#CAEEFF;font-size:14px;padding-left:25px;padding-top:30px'>${item.marker}${item.name}</div>
<div style='color:#31C2FF;font-size:16px;padding-left:25px;'>${item.seriesName}:${item.value}</div>
</div>`;
}
},
extraCssText:'box-shadow: none;'
},
color: color,
grid: {
top: '15%',
bottom: '54%',
left: '50%',
containLabel: false,
},
yAxis: [
{
type: 'category',
inverse: true,
axisLine: {
show: false,
},
axisTick: {
show: false,
},
axisLabel: {
formatter: function (params) {
let item = chartData[params];
console.log(item);
return '{name|' + item.name + '-}{percent|' + item.value + '}';
},
interval: 0,
inside: false,
textStyle: {
color: '#333',
fontSize: 14,
rich: {
name: {
color: 'rgba(202, 238, 255, 1)',
fontSize: 14,
},
bd: {
color: '#ccc',
padding: [0, 5],
fontSize: 14,
},
percent: {
color: 'rgba(202, 238, 255, 1)',
fontSize: 14,
},
value: {
color: '#333',
fontSize: 16,
fontWeight: 500,
padding: [0, 0, 0, 20],
},
},
},
show: true,
},
data: lineYAxis,
},
],
xAxis: [
{
show: false,
},
],
series: pieSeries,
};