index.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>ECharts</title>
  6. </head>
  7. <body>
  8. <!--Step:1 Prepare a dom for ECharts which (must) has size (width & hight)-->
  9. <!--Step:1 为ECharts准备一个具备大小(宽高)的Dom-->
  10. <div id="main" style="height:500px;border:1px solid #ccc;padding:10px;"></div>
  11. <div id="mainMap" style="height:500px;border:1px solid #ccc;padding:10px;"></div>
  12. <!--Step:2 Import echarts.js-->
  13. <!--Step:2 引入echarts.js-->
  14. <script src="js/echarts.js"></script>
  15. <script type="text/javascript">
  16. // Step:3 conifg ECharts's path, link to echarts.js from current page.
  17. // Step:3 为模块加载器配置echarts的路径,从当前页面链接到echarts.js,定义所需图表路径
  18. require.config({
  19. paths: {
  20. echarts: './js'
  21. }
  22. });
  23. // Step:4 require echarts and use it in the callback.
  24. // Step:4 动态加载echarts然后在回调函数中开始使用,注意保持按需加载结构定义图表路径
  25. require(
  26. [
  27. 'echarts',
  28. 'echarts/chart/bar',
  29. 'echarts/chart/line',
  30. 'echarts/chart/map'
  31. ],
  32. function (ec) {
  33. //--- 折柱 ---
  34. var myChart = ec.init(document.getElementById('main'));
  35. myChart.setOption({
  36. tooltip : {
  37. trigger: 'axis'
  38. },
  39. legend: {
  40. data:['蒸发量','降水量']
  41. },
  42. toolbox: {
  43. show : true,
  44. feature : {
  45. mark : {show: true},
  46. dataView : {show: true, readOnly: false},
  47. magicType : {show: true, type: ['line', 'bar']},
  48. restore : {show: true},
  49. saveAsImage : {show: true}
  50. }
  51. },
  52. calculable : true,
  53. xAxis : [
  54. {
  55. type : 'category',
  56. data : ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
  57. }
  58. ],
  59. yAxis : [
  60. {
  61. type : 'value',
  62. splitArea : {show : true}
  63. }
  64. ],
  65. series : [
  66. {
  67. name:'蒸发量',
  68. type:'bar',
  69. data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
  70. },
  71. {
  72. name:'降水量',
  73. type:'bar',
  74. data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
  75. }
  76. ]
  77. });
  78. // --- 地图 ---
  79. var myChart2 = ec.init(document.getElementById('mainMap'));
  80. myChart2.setOption({
  81. tooltip : {
  82. trigger: 'item',
  83. formatter: '{b}'
  84. },
  85. series : [
  86. {
  87. name: '中国',
  88. type: 'map',
  89. mapType: 'china',
  90. selectedMode : 'multiple',
  91. itemStyle:{
  92. normal:{label:{show:true}},
  93. emphasis:{label:{show:true}}
  94. },
  95. data:[
  96. {name:'广东',selected:true}
  97. ]
  98. }
  99. ]
  100. });
  101. }
  102. );
  103. </script>
  104. </body>
  105. </html>