dataset-layout.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="lib/esl.js"></script>
  5. <script src="lib/config.js"></script>
  6. <script src="lib/testHelper.js"></script>
  7. <meta name="viewport" content="width=device-width, initial-scale=1" />
  8. <link rel="stylesheet" href="lib/reset.css" />
  9. </head>
  10. <body>
  11. <style>
  12. .test-title {
  13. background: rgb(0, 112, 6);
  14. color: #fff;
  15. }
  16. </style>
  17. <div id="layout0"></div>
  18. <div id="layout1"></div>
  19. <div id="layout2"></div>
  20. <script>
  21. var arrayRows0 = [
  22. ['product', '2015', '2016', '2017'],
  23. ['Matcha Latte', 43.3, 85.8, 93.7],
  24. ['Milk Tea', 83.1, 73.4, 55.1],
  25. ['Cheese Cocoa', 86.4, 65.2, 82.5],
  26. ['Walnut Brownie', 72.4, 53.9, 39.1]
  27. ];
  28. var arrayRows1 = [
  29. ['product', '2012', '2013', '2014', '2015', '2016', '2017'],
  30. ['Matcha Latte', 41.1, 30.4, 65.1, 53.3, 83.8, 98.7],
  31. ['Milk Tea', 86.5, 92.1, 85.7, 83.1, 73.4, 55.1],
  32. ['Cheese Cocoa', 24.1, 67.2, 79.5, 86.4, 65.2, 82.5],
  33. ['Walnut Brownie', 55.2, 67.1, 69.2, 72.4, 53.9, 39.1]
  34. ];
  35. </script>
  36. <script>
  37. require(['echarts'], function (echarts) {
  38. var option = {
  39. legend: {},
  40. tooltip: {},
  41. xAxis: {type: 'category'},
  42. yAxis: {},
  43. dataset: {
  44. source: arrayRows0
  45. },
  46. series: [
  47. {type: 'bar'},
  48. {type: 'bar'},
  49. {type: 'bar'}
  50. ]
  51. };
  52. testHelper.create(echarts, 'layout0', {
  53. title: '[Default] seriesLayoutBy, enocde, name, head, legend',
  54. option: option,
  55. dataTable: arrayRows0
  56. });
  57. });
  58. </script>
  59. <script>
  60. require(['echarts'], function (echarts) {
  61. var option = {
  62. legend: {},
  63. tooltip: {},
  64. dataset: {
  65. source: arrayRows0
  66. },
  67. xAxis: [
  68. {type: 'category', gridIndex: 0},
  69. {type: 'category', gridIndex: 1}
  70. ],
  71. yAxis: [
  72. {gridIndex: 0},
  73. {gridIndex: 1}
  74. ],
  75. grid: [
  76. {bottom: '55%'},
  77. {top: '55%'}
  78. ],
  79. series: [
  80. {type: 'bar', xAxisIndex: 0, yAxisIndex: 0, label: {show: true, position: 'top'}},
  81. {type: 'bar', xAxisIndex: 0, yAxisIndex: 0, label: {show: true, position: 'top'}},
  82. {type: 'bar', xAxisIndex: 0, yAxisIndex: 0, label: {show: true, position: 'top'}},
  83. {type: 'bar', xAxisIndex: 1, yAxisIndex: 1, seriesLayoutBy: 'row'},
  84. {type: 'bar', xAxisIndex: 1, yAxisIndex: 1, seriesLayoutBy: 'row'},
  85. {type: 'bar', xAxisIndex: 1, yAxisIndex: 1, seriesLayoutBy: 'row'},
  86. {type: 'bar', xAxisIndex: 1, yAxisIndex: 1, seriesLayoutBy: 'row'},
  87. ]
  88. };
  89. testHelper.create(echarts, 'layout1', {
  90. title: 'seriesLayoutBy: "row" and "column" \n[Default] enocde, name, head, legend',
  91. option: option,
  92. dataTable: arrayRows0,
  93. height: 500,
  94. info: {
  95. grid: option.grid,
  96. series: option.series
  97. }
  98. });
  99. });
  100. </script>
  101. <script>
  102. require(['echarts'], function (echarts) {
  103. var option = {
  104. legend: {},
  105. tooltip: {
  106. trigger: 'axis',
  107. showContent: false
  108. },
  109. dataset: {
  110. source: arrayRows1
  111. },
  112. xAxis: {type: 'category'},
  113. yAxis: {gridIndex: 0},
  114. grid: {top: '55%'},
  115. series: [
  116. {type: 'line', smooth: true, seriesLayoutBy: 'row'},
  117. {type: 'line', smooth: true, seriesLayoutBy: 'row'},
  118. {type: 'line', smooth: true, seriesLayoutBy: 'row'},
  119. {type: 'line', smooth: true, seriesLayoutBy: 'row'},
  120. {
  121. type: 'pie',
  122. id: 'pie',
  123. radius: '30%',
  124. center: ['50%', '25%'],
  125. label: {
  126. formatter: '{b}: {@2012} ({d}%)'
  127. },
  128. encode: {
  129. itemName: 'product',
  130. value: '2012',
  131. tooltip: '2012'
  132. }
  133. }
  134. ]
  135. };
  136. var chart = testHelper.create(echarts, 'layout2', {
  137. title: 'seriesLayoutBy: row and column, setOption, pie \n [Default] enocde, name, head, legend',
  138. option: option,
  139. dataTable: arrayRows1,
  140. height: 500
  141. });
  142. chart && chart.on('updateAxisPointer', function (event) {
  143. var xAxisInfo = event.axesInfo[0];
  144. if (xAxisInfo) {
  145. var dimension = xAxisInfo.value + 1;
  146. chart.setOption({
  147. series: {
  148. id: 'pie',
  149. label: {
  150. formatter: '{b}: {@[' + dimension + ']} ({d}%)'
  151. },
  152. encode: {
  153. value: dimension,
  154. tooltip: dimension
  155. }
  156. }
  157. });
  158. }
  159. });
  160. });
  161. </script>
  162. </body>
  163. </html>