07a1cec9ffa03b4fc0ccab6316f8ac3af4faef59.svn-base 4.0 KB

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