bar-polar-real-estate.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="lib/esl.js"></script>
  5. <script src="lib/config.js"></script>
  6. <meta name="viewport" content="width=device-width, initial-scale=1" />
  7. </head>
  8. <body>
  9. <style>
  10. html, body, #main {
  11. width: 100%;
  12. height: 100%;
  13. margin: 0;
  14. }
  15. #main {
  16. background: #fff;
  17. }
  18. </style>
  19. <div id="main"></div>
  20. <script>
  21. require([
  22. 'echarts'
  23. // 'echarts/chart/bar',
  24. // 'echarts/component/legend',
  25. // 'echarts/component/polar',
  26. // 'echarts/component/title',
  27. // 'echarts/component/tooltip',
  28. // 'zrender/vml/vml'
  29. ], function (echarts) {
  30. var chart = echarts.init(document.getElementById('main'));
  31. var data = [
  32. [5000, 10000, 6785.71],
  33. [4000, 10000, 6825],
  34. [3000, 6500, 4463.33],
  35. [2500, 5600, 3793.83],
  36. [2000, 4000, 3060],
  37. [2000, 4000, 3222.33],
  38. [2500, 4000, 3133.33],
  39. [1800, 4000, 3100],
  40. [2000, 3500, 2750],
  41. [2000, 3000, 2500],
  42. [1800, 3000, 2433.33],
  43. [2000, 2700, 2375],
  44. [1500, 2800, 2150],
  45. [1500, 2300, 2100],
  46. [1600, 3500, 2057.14],
  47. [1500, 2600, 2037.5],
  48. [1500, 2417.54, 1905.85],
  49. [1500, 2000, 1775],
  50. [1500, 1800, 1650]
  51. ];
  52. var cities = ['北京', '上海', '深圳', '广州', '苏州', '杭州', '南京', '福州', '青岛', '济南', '长春', '大连', '温州', '郑州', '武汉', '成都', '东莞', '沈阳', '烟台'];
  53. var barHeight = 50;
  54. chart.setOption({
  55. title: {
  56. text: '在中国租个房子有多贵?',
  57. subtext: '市中心一室月租费(数据来源:https://www.numbeo.com)'
  58. },
  59. legend: {
  60. show: true,
  61. data: ['价格范围', '均值']
  62. },
  63. grid: {
  64. top: 100
  65. },
  66. angleAxis: {
  67. type: 'category',
  68. data: cities
  69. },
  70. tooltip: {
  71. show: true,
  72. formatter: function (params) {
  73. var id = params.dataIndex;
  74. return cities[id] + '<br>最高:' + data[id][0] + '<br>最低:' + data[id][1] + '<br>平均:' + data[id][2];
  75. }
  76. },
  77. radiusAxis: {
  78. },
  79. polar: {
  80. },
  81. series: [{
  82. type: 'bar',
  83. itemStyle: {
  84. normal: {
  85. color: 'transparent'
  86. }
  87. },
  88. data: data.map(function (d) {
  89. return d[0];
  90. }),
  91. coordinateSystem: 'polar',
  92. stack: '最大最小值',
  93. silent: true
  94. }, {
  95. type: 'bar',
  96. data: data.map(function (d) {
  97. return d[1] - d[0];
  98. }),
  99. coordinateSystem: 'polar',
  100. name: '价格范围',
  101. stack: '最大最小值'
  102. }, {
  103. type: 'bar',
  104. itemStyle: {
  105. normal: {
  106. color: 'transparent'
  107. }
  108. },
  109. data: data.map(function (d) {
  110. return d[2] - barHeight;
  111. }),
  112. coordinateSystem: 'polar',
  113. stack: '均值',
  114. silent: true,
  115. z: 10
  116. }, {
  117. type: 'bar',
  118. data: data.map(function (d) {
  119. return barHeight * 2
  120. }),
  121. coordinateSystem: 'polar',
  122. name: '均值',
  123. stack: '均值',
  124. barGap: '-100%',
  125. z: 10
  126. }],
  127. legend: {
  128. show: true,
  129. data: ['A', 'B', 'C']
  130. }
  131. });
  132. chart.on('click', function (params) {
  133. console.log(params);
  134. });
  135. window.onresize = chart.resize;
  136. });
  137. </script>
  138. </body>
  139. </html>