function echarts_31() { var myChart = echarts.init(document.getElementById('fb1')); var data = Chart31_Data; var option = { title: { text: '天气状况统计', // subtext: '数据来源:气象局', left: 'center', textStyle: { color: '#fff', fontSize: '16' } }, tooltip: { trigger: 'item', position: function (p) { //其中p为当前鼠标的位置 return [p[0] + 60, p[1] - 70]; }, formatter: function (params) { var dataItem = data.find(item => item.name === params.name); var value = `${dataItem.name}: ${params.value} (${params.percent}%)
`; dataItem.weather.forEach((v, index) => { value += `${v} `; if (index % 3 === 1) { value += '
'; } }); return value; // 动态遍历数据显示地区、天气和百分比 } }, legend: { orient: 'vertical', left: 'left', top: '70%', itemWidth: 10, itemHeight: 10, textStyle: { color: 'rgba(255,255,255,.5)', fontSize: '12', }, }, series: [ { name: '天气状况', type: 'pie', center: ['50%', '42%'], radius: ['40%', '60%'], avoidLabelOverlap: false, label: { show: false, position: 'center', formatter: '{b}: {c}' // 显示地区名称和天气数据 }, emphasis: { label: { show: true, fontSize: '30', fontWeight: 'bold' } }, labelLine: { show: false }, data: data.map(item => ({ value: item.value, name: item.name, itemStyle: {color: item.color}, label: { normal: { show: false // 设置标签显示为normal } } })) } ] }; myChart.setOption(option); window.addEventListener("resize", function () { myChart.resize(); }); }