show.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>ECharts 实例</title>
  6. <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
  7. <!-- 引入 echarts.js -->
  8. <script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>
  9. </head>
  10. <body>
  11. <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
  12. <div id="main" style="width: 600px;height:400px;"></div>
  13. <script type="text/javascript">
  14. // 基于准备好的dom,初始化echarts实例
  15. var myChart = echarts.init(document.getElementById('main'));
  16. // 指定图表的配置项和数据
  17. $.get('https://www.runoob.com/static/js/life-expectancy-table.json', function (data) {
  18. var sizeValue = '57%';
  19. var symbolSize = 2.5;
  20. option = {
  21. legend: {},
  22. tooltip: {},
  23. toolbox: {
  24. left: 'center',
  25. feature: {
  26. dataZoom: {}
  27. }
  28. },
  29. grid: [
  30. {right: sizeValue, bottom: sizeValue},
  31. {left: sizeValue, bottom: sizeValue},
  32. {right: sizeValue, top: sizeValue},
  33. {left: sizeValue, top: sizeValue}
  34. ],
  35. xAxis: [
  36. {type: 'value', gridIndex: 0, name: 'Income', axisLabel: {rotate: 50, interval: 0}},
  37. {type: 'category', gridIndex: 1, name: 'Country', boundaryGap: false, axisLabel: {rotate: 50, interval: 0}},
  38. {type: 'value', gridIndex: 2, name: 'Income', axisLabel: {rotate: 50, interval: 0}},
  39. {type: 'value', gridIndex: 3, name: 'Life Expectancy', axisLabel: {rotate: 50, interval: 0}}
  40. ],
  41. yAxis: [
  42. {type: 'value', gridIndex: 0, name: 'Life Expectancy'},
  43. {type: 'value', gridIndex: 1, name: 'Income'},
  44. {type: 'value', gridIndex: 2, name: 'Population'},
  45. {type: 'value', gridIndex: 3, name: 'Population'}
  46. ],
  47. dataset: {
  48. dimensions: [
  49. 'Income',
  50. 'Life Expectancy',
  51. 'Population',
  52. 'Country',
  53. {name: 'Year', type: 'ordinal'}
  54. ],
  55. source: data
  56. },
  57. series: [
  58. {
  59. type: 'scatter',
  60. symbolSize: symbolSize,
  61. xAxisIndex: 0,
  62. yAxisIndex: 0,
  63. encode: {
  64. x: 'Income',
  65. y: 'Life Expectancy',
  66. tooltip: [0, 1, 2, 3, 4]
  67. }
  68. },
  69. {
  70. type: 'scatter',
  71. symbolSize: symbolSize,
  72. xAxisIndex: 1,
  73. yAxisIndex: 1,
  74. encode: {
  75. x: 'Country',
  76. y: 'Income',
  77. tooltip: [0, 1, 2, 3, 4]
  78. }
  79. },
  80. {
  81. type: 'scatter',
  82. symbolSize: symbolSize,
  83. xAxisIndex: 2,
  84. yAxisIndex: 2,
  85. encode: {
  86. x: 'Income',
  87. y: 'Population',
  88. tooltip: [0, 1, 2, 3, 4]
  89. }
  90. },
  91. {
  92. type: 'scatter',
  93. symbolSize: symbolSize,
  94. xAxisIndex: 3,
  95. yAxisIndex: 3,
  96. encode: {
  97. x: 'Life Expectancy',
  98. y: 'Population',
  99. tooltip: [0, 1, 2, 3, 4]
  100. }
  101. }
  102. ]
  103. };
  104. myChart.setOption(option);
  105. });
  106. </script>
  107. </body>
  108. </html>