|
@@ -178,6 +178,8 @@ export default {
|
|
|
barChart: null,
|
|
|
pieChart: null,
|
|
|
mapChart: null,
|
|
|
+ chinaPieData: [],
|
|
|
+ worldPieData: [],
|
|
|
form:{
|
|
|
batch: "",
|
|
|
bytName: "",
|
|
@@ -194,6 +196,19 @@ export default {
|
|
|
// this.initRegionOptions();
|
|
|
this.fetchAllData()
|
|
|
this.initCharts();
|
|
|
+ // 地图点击切换
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.mapChart.on('click', params => {
|
|
|
+ console.log('地图点击:', params);
|
|
|
+ if (params && params.name === 'China' && !this.isChinaMap) {
|
|
|
+ this.isChinaMap = true;
|
|
|
+ this.fetchAllData();
|
|
|
+ } else if (params && params.name !== 'China' && this.isChinaMap) {
|
|
|
+ this.isChinaMap = false;
|
|
|
+ this.fetchAllData();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
},
|
|
|
methods: {
|
|
|
async searchDisease(query) {
|
|
@@ -247,47 +262,14 @@ export default {
|
|
|
const response4 = await getzgbytztqkInfo(this.form);
|
|
|
this.growthData = response.data;
|
|
|
this.barData = response2.data;
|
|
|
+ this.worldPieData = response3.data;
|
|
|
+ this.chinaPieData = response4.data;
|
|
|
+ this.mapData = this.isChinaMap ? this.chinaPieData : this.worldPieData;
|
|
|
} catch (error) {
|
|
|
console.error('获取数据失败:', error);
|
|
|
this.$message.error('获取数据失败,请稍后重试');
|
|
|
}
|
|
|
|
|
|
- // // 联动下拉框
|
|
|
- // if (this.filters.disease) {
|
|
|
- // // 假数据
|
|
|
- // this.subtypeOptions = ['亚型 1', '亚型 2', '亚型 3'];
|
|
|
- // }
|
|
|
- // if (this.filters.subtype) {
|
|
|
- // // 假数据
|
|
|
- // this.branchOptions = ['分支 A', '分支 B', '分支 C'];
|
|
|
- // }
|
|
|
- // // 获取假数据
|
|
|
- // this.growthData = [
|
|
|
- // { date: '2025-06-01', value: 10, ratio: 10, count: 5 },
|
|
|
- // { date: '2025-06-02', value: 20, ratio: 20, count: 8 }
|
|
|
- // ];
|
|
|
- // this.barData = [
|
|
|
- // { region: '中国', count: 100, percent: 60 },
|
|
|
- // { region: '美国', count: 80, percent: 40 }
|
|
|
- // ];
|
|
|
- // this.mapData = this.isChinaMap
|
|
|
- // ? Object.keys(chinaPieData).map(name => {
|
|
|
- // const geoCoord = chinaGeoCoordMap[name] || [0, 0]; // 若经纬度不存在,使用默认值 [0, 0]
|
|
|
- // return {
|
|
|
- // name,
|
|
|
- // value: [...geoCoord, chinaPieData[name].reduce((sum, item) => sum + item.value, 0)],
|
|
|
- // data: chinaPieData[name]
|
|
|
- // };
|
|
|
- // })
|
|
|
- // : Object.keys(worldPieData).map(name => {
|
|
|
- // const geoCoord = worldGeoCoordMap[name] || [0, 0]; // 若经纬度不存在,使用默认值 [0, 0]
|
|
|
- // return {
|
|
|
- // name,
|
|
|
- // value: [...geoCoord, worldPieData[name].reduce((sum, item) => sum + item.value, 0)],
|
|
|
- // data: worldPieData[name]
|
|
|
- // };
|
|
|
- // });
|
|
|
- // this.description = '这是一段假的数据分析文本。';
|
|
|
this.renderCharts();
|
|
|
},
|
|
|
initCharts() {
|
|
@@ -366,93 +348,69 @@ export default {
|
|
|
// 使用动态生成的系列数据
|
|
|
series: seriesData
|
|
|
});
|
|
|
- // 子图三:分支饼图
|
|
|
- // this.pieChart.setOption({
|
|
|
- // tooltip: {
|
|
|
- // trigger: 'item',
|
|
|
- // formatter: '{b}: {c} ({d}%)'
|
|
|
- // },
|
|
|
- // series: [{
|
|
|
- // type: 'pie',
|
|
|
- // radius: '60%',
|
|
|
- // data: this.pieData
|
|
|
- // }]
|
|
|
- // })
|
|
|
// // 地图
|
|
|
- // this.mapChart.setOption({
|
|
|
- // tooltip: {
|
|
|
- // trigger: 'item',
|
|
|
- // formatter: p => {
|
|
|
- // if (p.seriesType === 'scatter') {
|
|
|
- // const total = p.data.value[2];
|
|
|
- // const pieData = p.data.data;
|
|
|
- // let tooltipStr = `${p.name}<br/>总分支数: ${total}<br/>`;
|
|
|
- // if (pieData) {
|
|
|
- // pieData.forEach(item => {
|
|
|
- // const percent = ((item.value / total) * 100).toFixed(2);
|
|
|
- // tooltipStr += `${item.name}: ${item.value} (${percent}%)<br/>`;
|
|
|
- // });
|
|
|
- // } else {
|
|
|
- // tooltipStr += '暂无分支数据<br/>';
|
|
|
- // }
|
|
|
- // return tooltipStr;
|
|
|
- // }
|
|
|
- // return p.name;
|
|
|
- // }
|
|
|
- // },
|
|
|
- // // 添加 geo 组件,用于显示地图背景
|
|
|
- // geo: {
|
|
|
- // map: this.isChinaMap ? 'china' : 'world',
|
|
|
- // roam: true,
|
|
|
- // // 设置中国地图和世界地图的中心位置和缩放级别
|
|
|
- // center: this.isChinaMap ? [104.1954, 35.8617] : [10, 10],
|
|
|
- // zoom: this.isChinaMap ? 2 : 1.2,
|
|
|
- // label: {
|
|
|
- // emphasis: {
|
|
|
- // show: false
|
|
|
- // }
|
|
|
- // },
|
|
|
- // itemStyle: {
|
|
|
- // normal: {
|
|
|
- // // 修改为浅色背景,这里使用浅灰色作为示例
|
|
|
- // areaColor: '#f0f0f0',
|
|
|
- // borderColor: '#999'
|
|
|
- // },
|
|
|
- // emphasis: {
|
|
|
- // // 修改为稍深一点的浅色,用于鼠标悬停状态
|
|
|
- // areaColor: '#e0e0e0'
|
|
|
- // }
|
|
|
- // }
|
|
|
- // },
|
|
|
- // series: [
|
|
|
- // {
|
|
|
- // type: 'scatter',
|
|
|
- // coordinateSystem: 'geo',
|
|
|
- // data: this.mapData,
|
|
|
- // symbolSize: val => Math.sqrt(val[2]) * 2,
|
|
|
- // label: {
|
|
|
- // show: true,
|
|
|
- // formatter: '{b}'
|
|
|
- // },
|
|
|
- // itemStyle: {
|
|
|
- // color: 'rgba(255, 0, 0, 0.8)'
|
|
|
- // },
|
|
|
- // emphasis: {
|
|
|
- // itemStyle: {
|
|
|
- // color: 'red'
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // ]
|
|
|
- // });
|
|
|
- // // 地图点击切换
|
|
|
- // this.mapChart.off('click');
|
|
|
- // this.mapChart.on('click', params => {
|
|
|
- // if (!this.isChinaMap && params.name === '中国') {
|
|
|
- // this.isChinaMap = true;
|
|
|
- // this.fetchAllData();
|
|
|
- // }
|
|
|
- // });
|
|
|
+ // 处理 mapData 数据,转换为符合 ECharts 要求的格式
|
|
|
+ const processedMapData = this.mapData.map(item => {
|
|
|
+ const [lat, lng] = item.latlng.split(',').map(Number);
|
|
|
+ return {
|
|
|
+ name: item.area,
|
|
|
+ value: [lng, lat, item.num],
|
|
|
+ num: item.num
|
|
|
+ };
|
|
|
+ });
|
|
|
+ this.mapChart.setOption({
|
|
|
+ title: { text: '病毒预测分布', left: 'center' },
|
|
|
+ tooltip: {
|
|
|
+ trigger: 'item',
|
|
|
+ formatter: p => `${p.name}<br/>数量: ${p.data ? p.data.num : '-'}`
|
|
|
+ },
|
|
|
+ visualMap: {
|
|
|
+ min: 0,
|
|
|
+ max: 150,
|
|
|
+ left: 'left',
|
|
|
+ top: 'bottom',
|
|
|
+ text: ['高', '低'],
|
|
|
+ calculable: true,
|
|
|
+ inRange: {
|
|
|
+ color: ['#e0f3f8', '#abd9e9', '#74add1', '#4575b4', '#313695'] // 颜色深浅
|
|
|
+ }
|
|
|
+ },
|
|
|
+ geo: {
|
|
|
+ map: this.isChinaMap ? 'china' : 'world',
|
|
|
+ roam: true,
|
|
|
+ label: { show: false },
|
|
|
+ itemStyle: {
|
|
|
+ areaColor: '#f0f0f0',
|
|
|
+ borderColor: '#999'
|
|
|
+ },
|
|
|
+ emphasis: {
|
|
|
+ itemStyle: {
|
|
|
+ areaColor: '#e0e0e0'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ series: [
|
|
|
+ {
|
|
|
+ type: 'scatter',
|
|
|
+ coordinateSystem: 'geo',
|
|
|
+ data: processedMapData,
|
|
|
+ symbolSize: val => Math.max(8, Math.sqrt(val[2]) * 2), // 数量越大点越大
|
|
|
+ encode: { value: 2 },
|
|
|
+ label: {
|
|
|
+ show: false
|
|
|
+ },
|
|
|
+ itemStyle: {
|
|
|
+ color: '#4575b4'
|
|
|
+ },
|
|
|
+ emphasis: {
|
|
|
+ itemStyle: {
|
|
|
+ color: '#d73027'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+});
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
};
|