dataView.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. <script src=""></script>
  7. <script src="//cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
  8. <link rel="stylesheet" href="//cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css">
  9. <meta name="viewport" content="width=device-width, initial-scale=1" />
  10. </head>
  11. <body>
  12. <style>
  13. html, body, #main {
  14. width: 100%;
  15. height: 100%;
  16. margin: 0;
  17. }
  18. #main {
  19. background: #fff;
  20. }
  21. </style>
  22. <div id="main"></div>
  23. <script>
  24. require([
  25. 'echarts',
  26. 'echarts/chart/bar',
  27. 'echarts/chart/line',
  28. 'echarts/component/legend',
  29. 'echarts/component/grid',
  30. 'echarts/component/tooltip',
  31. 'echarts/component/toolbox',
  32. 'zrender/vml/vml'
  33. ], function (echarts) {
  34. var chart = echarts.init(document.getElementById('main'));
  35. var xAxisData = [];
  36. var data1 = [];
  37. var data2 = [];
  38. var data3 = [];
  39. var data4 = [];
  40. for (var i = 0; i < 10; i++) {
  41. xAxisData.push('类目' + i);
  42. data1.push((Math.random() * 5).toFixed(2));
  43. data2.push(-Math.random().toFixed(2));
  44. data3.push((Math.random() + 0.5).toFixed(2));
  45. data4.push((Math.random() + 0.3).toFixed(2));
  46. }
  47. chart.setOption({
  48. toolbox: {
  49. // y: 'bottom',
  50. feature: {
  51. dataView: {
  52. optionToContent: function(opt) {
  53. var axisData = opt.xAxis[0].data;
  54. var series = opt.series;
  55. var table = '<table style="width:100%;text-align:center"><tbody><tr>'
  56. + '<td>时间</td>'
  57. + '<td>' + series[0].name + '</td>'
  58. + '<td>' + series[1].name + '</td>'
  59. + '</tr>';
  60. for (var i = 0, l = axisData.length; i < l; i++) {
  61. table += '<tr>'
  62. + '<td>' + axisData[i] + '</td>'
  63. + '<td>' + series[0].data[i] + '</td>'
  64. + '<td>' + series[1].data[i] + '</td>'
  65. + '</tr>';
  66. }
  67. table += '</tbody></table>';
  68. return table;
  69. },
  70. contentToOption: function () {
  71. console.log(arguments);
  72. }
  73. },
  74. saveAsImage: {
  75. pixelRatio: 2
  76. }
  77. }
  78. },
  79. tooltip: {},
  80. xAxis: {
  81. data: xAxisData,
  82. axisLine: {
  83. onZero: true
  84. },
  85. splitLine: {
  86. show: false
  87. },
  88. splitArea: {
  89. show: false
  90. }
  91. },
  92. yAxis: {
  93. inverse: true,
  94. splitArea: {
  95. show: false
  96. }
  97. },
  98. series: [{
  99. name: 'bar',
  100. type: 'bar',
  101. stack: 'one',
  102. data: data1
  103. }, {
  104. name: 'bar2',
  105. type: 'bar',
  106. stack: 'one',
  107. data: data2
  108. }, {
  109. name: 'bar3',
  110. type: 'bar',
  111. stack: 'two',
  112. data: data3
  113. }, {
  114. name: 'bar4',
  115. type: 'bar',
  116. stack: 'two',
  117. data: data4
  118. }]
  119. });
  120. window.onresize = chart.resize;
  121. });
  122. </script>
  123. </body>
  124. </html>