2
schangxiang@126.com
2024-08-16 b47c50a2a514def7374b32d7194b2c599cba5625
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
function option2 (idx, selected) {
    var option = {
        tooltip : {
            trigger: 'item'
        },
        toolbox: {
            //orient: 'vertical',
            x: 'center',
            y: 'top',
            show : true,
            feature : {
                mark : {show: true},
                dataZoom : {show: true},
                dataView : {show: true, readOnly: false},
                restore : {show: true},
                saveAsImage : {show: true}
            }
        },
        legend : {
            data: ['城市'],
            selectedMode: false,
            orient: 'vertical',
            x: 'right'
        },
        grid: {
            x : 45,
            y : 30,
            x2 : 35,
            y2 : 30,
        },
        xAxis : [
            {
                name: idx != 0 ? 'PM25' : '亿元',
                type : 'value',
                //power: 1,
                scale: false
            }
        ],
        yAxis : [
            {
                name: idx != 1 ? '万人' : '亿元',
                type : 'value',
                //power: 1,
                scale: false,
                splitArea : {show : true}
            }
        ],
        animation:false,
        series : [
            {
                name:'城市',
                type:'scatter',
                
                symbolSize: function (value){
                    return Math.round(value[2] / sizeCtrl);
                }
            }
        ]
    };
    
    var scatterData = [];
    var sizeCtrl;
    var tipFormatter;
    switch(idx+'') {
        case '0':
            sizeCtrl = 10;
            tipFormatter = function (v) {
                return v[1] + '<br>'
                       + 'GDP : ' + v[2][0] + '(亿元)<br/>'
                       + '人口 : ' + v[2][1] + '(万人)<br/>'
                       + 'PM2.5 : ' + v[2][2];
            }
            for (var city in selected) {
                if (selected[city]) {
                    scatterData.push({
                        name: city,
                        value: [
                            PG[city].gdp,
                            PG[city].pop,
                            data.cityToData[city].pm2_5
                        ],
                        itemStyle:{normal:{color:PG[city].color}}
                    });
                }
            }
            break;
        case '1':
            sizeCtrl = 80;
            tipFormatter = function (v) {
                return v[1] + '<br>'
                       + 'PM2.5 : ' + v[2][0] + '<br/>'
                       + 'GDP : ' + v[2][1] + '(亿元)<br/>'
                       + '人口 : ' + v[2][2] + '(万人)';
            }
            for (var city in selected) {
                if (selected[city]) {
                    scatterData.push({
                        name: city,
                        value: [
                            data.cityToData[city].pm2_5,
                            PG[city].gdp,
                            PG[city].pop
                        ],
                        itemStyle:{normal:{color:PG[city].color}}
                    });
                }
            }
            break;
        case '2':
            sizeCtrl = 500;
            tipFormatter = function (v) {
                return v[1] + '<br>'
                       + 'PM2.5  : ' + v[2][0] + '<br/>'
                       + '人口  : ' + v[2][1] + '(万人)<br/>'
                       + 'GDP : ' + v[2][2] + '(亿元)';
            }
            for (var city in selected) {
                if (selected[city]) {
                    scatterData.push({
                        name: city,
                        value: [
                            data.cityToData[city].pm2_5,
                            PG[city].pop,
                            PG[city].gdp
                        ],
                        itemStyle:{normal:{color:PG[city].color}}
                    });
                }
            }
    }
    option.tooltip.formatter = tipFormatter;
    option.series[0].data = scatterData;
    
    return option;
}