boxplot-multi.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <meta name="viewport" content="width=device-width, initial-scale=1" />
  5. <script src="esl.js"></script>
  6. <script src="config.js"></script>
  7. <script src="lib/facePrint.js"></script>
  8. <script src="lib/dat.gui.min.js"></script>
  9. </head>
  10. <body>
  11. <style>
  12. html, body, #main {
  13. width: 100%;
  14. height: 100%;
  15. }
  16. </style>
  17. <div id="info"></div>
  18. <div id="main"></div>
  19. <script>
  20. var chart;
  21. var data;
  22. require([
  23. 'echarts',
  24. 'extension/dataTool/prepareBoxplotData',
  25. 'echarts/chart/boxplot',
  26. 'echarts/chart/scatter',
  27. 'echarts/component/title',
  28. 'echarts/component/legend',
  29. 'echarts/component/grid',
  30. 'echarts/component/tooltip',
  31. 'echarts/component/dataZoom'
  32. ], function (echarts, prepareBoxplotData) {
  33. chart = echarts.init(document.getElementById('main'), null, {
  34. renderer: 'canvas'
  35. });
  36. function update(layout) {
  37. // Generate data.
  38. data = [];
  39. for (var seriesIndex = 0; seriesIndex < 5; seriesIndex++) {
  40. var seriesData = [];
  41. for (var i = 0; i < 18; i++) {
  42. var cate = [];
  43. for (var j = 0; j < 100; j++) {
  44. cate.push(Math.random() * 200);
  45. }
  46. seriesData.push(cate);
  47. }
  48. data.push(prepareBoxplotData(seriesData, {
  49. layout: layout
  50. }));
  51. }
  52. var categoryAxis = {
  53. type: 'category',
  54. data: data[0].axisData,
  55. boundaryGap: true,
  56. nameGap: 30,
  57. splitArea: {
  58. show: true
  59. },
  60. axisLabel: {
  61. formatter: 'expr {value}'
  62. },
  63. splitLine: {
  64. show: false
  65. }
  66. };
  67. var valueAxis = {
  68. type: 'value',
  69. name: 'Value',
  70. splitArea: {
  71. show: false
  72. }
  73. };
  74. chart.setOption({
  75. title: [
  76. {
  77. text: 'Multiple Categories',
  78. left: 'center',
  79. }
  80. ],
  81. legend: {
  82. top: '10%',
  83. data: ['category0', 'category1', 'category2', 'category3']
  84. },
  85. tooltip: {
  86. trigger: 'item',
  87. axisPointer: {
  88. type: 'shadow'
  89. }
  90. },
  91. grid: {
  92. left: '10%',
  93. top: '20%',
  94. right: '10%',
  95. bottom: '15%'
  96. },
  97. xAxis: layout === 'horizontal' ? categoryAxis : valueAxis,
  98. yAxis: layout === 'vertical' ? categoryAxis : valueAxis,
  99. dataZoom: [
  100. {
  101. type: 'inside',
  102. start: 0,
  103. end: 20
  104. },
  105. {
  106. show: true,
  107. height: 20,
  108. type: 'slider',
  109. bottom: 50,
  110. xAxisIndex: layout === 'horizontal' ? [0] : [],
  111. yAxisIndex: layout === 'horizontal' ? [] : [0],
  112. start: 0,
  113. end: 20
  114. }
  115. ],
  116. series: [
  117. {
  118. name: 'category0',
  119. type: 'boxplot',
  120. data: data[0].boxData,
  121. tooltip: {formatter: formatter}
  122. },
  123. {
  124. name: 'category1',
  125. type: 'boxplot',
  126. data: data[1].boxData,
  127. tooltip: {formatter: formatter}
  128. },
  129. {
  130. name: 'category2',
  131. type: 'boxplot',
  132. data: data[2].boxData,
  133. tooltip: {formatter: formatter}
  134. }
  135. ]
  136. });
  137. }
  138. function formatter(param) {
  139. return [
  140. 'Experiment ' + param.name + ': ',
  141. 'upper: ' + param.data[0],
  142. 'Q1: ' + param.data[1],
  143. 'median: ' + param.data[2],
  144. 'Q3: ' + param.data[3],
  145. 'lower: ' + param.data[4]
  146. ].join('<br/>')
  147. }
  148. // var gui = new dat.GUI();
  149. // var config = {
  150. // layout: 'horizontal'
  151. // };
  152. // gui
  153. // .add(config, 'layout', ['horizontal', 'vertical'])
  154. // .onChange(update);
  155. update('horizontal');
  156. })
  157. </script>
  158. </body>
  159. </html>