encode.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. h1 {
  13. line-height: 60px;
  14. height: 60px;
  15. background: #ddd;
  16. text-align: center;
  17. font-weight: bold;
  18. font-size: 14px;
  19. }
  20. .chart {
  21. height: 350px;
  22. }
  23. </style>
  24. <h1>define dim name in tooltip</h1>
  25. <div class="chart" id="dim"></div>
  26. <h1>change tooltip order (Tooltip of the first series should be: median, 1分位, Q3)</h1>
  27. <div class="chart" id="order"></div>
  28. <h1>define which dim on x or y. encode: {x: 2, y: 1, label: 4}</h1>
  29. <div class="chart" id="dimXY"></div>
  30. <script>
  31. require([
  32. 'echarts',
  33. 'data/security-sh-2013.json'
  34. // 'echarts/chart/line',
  35. // 'echarts/chart/candlestick',
  36. // 'echarts/component/legend',
  37. // 'echarts/component/grid',
  38. // 'echarts/component/tooltip',
  39. // 'zrender/vml/vml'
  40. ], function (echarts, rawData) {
  41. var dom = document.getElementById('dim');
  42. if (!dom) {
  43. return;
  44. }
  45. var chart = echarts.init(dom);
  46. function splitData(rawData) {
  47. var categoryData = [];
  48. var values = []
  49. for (var i = 0; i < rawData.length; i++) {
  50. categoryData.push(rawData[i].splice(0, 1)[0]);
  51. values.push(rawData[i])
  52. }
  53. return {
  54. categoryData: categoryData,
  55. values: values
  56. };
  57. }
  58. var data = splitData(rawData);
  59. chart.setOption({
  60. legend: {
  61. data: ['上证指数', '开盘']
  62. },
  63. tooltip: {
  64. trigger: 'axis',
  65. axisPointer: {
  66. type: 'line'
  67. }
  68. },
  69. grid: {
  70. left: '10%',
  71. right: '10%',
  72. bottom: '15%'
  73. },
  74. xAxis: {
  75. type: 'category',
  76. data: data.categoryData,
  77. scale: true,
  78. boundaryGap : false,
  79. axisLine: {onZero: false},
  80. splitLine: {show: false},
  81. splitNumber: 20,
  82. min: 'dataMin',
  83. max: 'dataMax'
  84. },
  85. yAxis: {
  86. scale: true,
  87. splitArea: {
  88. show: true
  89. }
  90. },
  91. dataZoom: [
  92. {
  93. type: 'inside',
  94. start: 50,
  95. end: 100
  96. },
  97. {
  98. show: true,
  99. type: 'slider',
  100. y: '90%',
  101. start: 50,
  102. end: 100
  103. }
  104. ],
  105. series: [
  106. {
  107. name: 'line',
  108. type: 'line',
  109. data: (function () {
  110. opens = [];
  111. for (var i = 0, len = data.values.length; i < len; i++) {
  112. opens.push(data.values[i][0]);
  113. }
  114. return opens;
  115. })(),
  116. smooth: true,
  117. lineStyle: {
  118. normal: {color: '#aaa'}
  119. }
  120. },
  121. {
  122. name: '上证指数',
  123. type: 'candlestick',
  124. dimensions: ['base', '开盘', '收盘', '最高', '最低'],
  125. data: data.values
  126. }
  127. ]
  128. });
  129. })
  130. </script>
  131. <script>
  132. var chart;
  133. var data;
  134. require([
  135. 'echarts',
  136. 'extension/dataTool'
  137. // 'echarts/chart/boxplot',
  138. // 'echarts/chart/scatter',
  139. // 'echarts/component/title',
  140. // 'echarts/component/legend',
  141. // 'echarts/component/grid',
  142. // 'echarts/component/tooltip',
  143. // 'echarts/component/dataZoom'
  144. ], function (echarts, dataTool) {
  145. var prepareBoxplotData = dataTool.prepareBoxplotData;
  146. data = [];
  147. for (var seriesIndex = 0; seriesIndex < 5; seriesIndex++) {
  148. var seriesData = [];
  149. for (var i = 0; i < 18; i++) {
  150. var cate = [];
  151. for (var j = 0; j < 100; j++) {
  152. cate.push(Math.random() * 200);
  153. }
  154. seriesData.push(cate);
  155. }
  156. data.push(prepareBoxplotData(seriesData, {layout: 'horizontal'}));
  157. }
  158. var option = {
  159. title: [
  160. {
  161. text: 'Multiple Categories',
  162. left: 'center',
  163. }
  164. ],
  165. legend: {
  166. top: '10%',
  167. data: ['category0', 'category1', 'category2', 'category3']
  168. },
  169. tooltip: {
  170. trigger: 'axis',
  171. axisPointer: {
  172. type: 'shadow'
  173. }
  174. },
  175. grid: {
  176. left: '10%',
  177. top: '20%',
  178. right: '10%',
  179. bottom: '15%'
  180. },
  181. xAxis: {
  182. type: 'category',
  183. data: data[0].axisData,
  184. boundaryGap: true,
  185. nameGap: 30,
  186. splitArea: {
  187. show: true
  188. },
  189. axisLabel: {
  190. formatter: 'expr {value}'
  191. },
  192. splitLine: {
  193. show: false
  194. }
  195. },
  196. yAxis: {
  197. type: 'value',
  198. name: 'Value',
  199. splitArea: {
  200. show: false
  201. }
  202. },
  203. dataZoom: [
  204. {
  205. type: 'inside',
  206. start: 0,
  207. end: 20
  208. },
  209. {
  210. show: true,
  211. height: 20,
  212. type: 'slider',
  213. bottom: 50,
  214. xAxisIndex: [0],
  215. yAxisIndex: [],
  216. start: 0,
  217. end: 20
  218. }
  219. ],
  220. series: [
  221. {
  222. name: 'category0',
  223. type: 'boxplot',
  224. dimensions: [null, '最小', '1分位'],
  225. encode: {
  226. tooltip: [3, 2, 4]
  227. },
  228. data: data[0].boxData
  229. },
  230. {
  231. name: 'category1',
  232. type: 'boxplot',
  233. data: data[1].boxData
  234. }
  235. ]
  236. };
  237. testHelper.createChart(echarts, 'order', option);
  238. })
  239. </script>
  240. <script>
  241. require([
  242. 'echarts'
  243. // 'echarts/chart/scatter',
  244. // 'echarts/component/legend',
  245. // 'echarts/component/visualMap',
  246. // 'echarts/component/dataZoom',
  247. // 'zrender/vml/vml'
  248. ], function (echarts) {
  249. data = [
  250. ['Blouse "Blue Viola"', 101.88, 99.75, 23, 17, 32, 18],
  251. ['Dress "Daisy"', 155.8, 144.03, 18, 12, 26, 33],
  252. ['Trousers "Cutesy Classic"', 203.25, 173.56, 22, 14, 20, 46],
  253. ['Dress "Morning Dew"', 256.0, 120.5, 22, 16, 20, 23],
  254. ['Turtleneck "Dark Chocolate"', 408.89, 294.75, 18, 22, 23, 19],
  255. ['Jumper "Early Spring"', 427.36, 430.24, 23, 22, 28, 34],
  256. ['Breeches "Summer Mood"', 356.0, 135.5, 12, 16, 23, 31],
  257. ['Dress "Mauve Chamomile"', 406.0, 95.5, 22, 16, 40, 23],
  258. ['Dress "Flying Tits"', 527.36, 503.24, 15, 22, 42, 24],
  259. ['Dress "Singing Nightingales"', 587.36, 543.24, 25, 12, 28, 37],
  260. ['Sundress "Cloudy weather"', 603.36, 407.24, 15, 12, 22, 24],
  261. ['Sundress "East motives"', 633.36, 477.24, 32, 10, 39, 19],
  262. ['Sweater "Cold morning"', 517.36, 437.24, 21, 17, 29, 48],
  263. ['Trousers "Lavender Fields"', 443.36, 387.24, 17, 26, 31, 41],
  264. ['Jumper "Coffee with Milk"', 543.36, 307.24, 19, 10, 34, 31],
  265. ['Blouse "Blooming Cactus"', 790.36, 277.24, 23, 18, 26, 28],
  266. ['Sweater "Fluffy Comfort"', 790.34, 678.34, 18, 12, 28, 34]
  267. ];
  268. var encode = {
  269. x: 0,
  270. y: [1, 2]
  271. };
  272. var option = {
  273. tooltip: {
  274. axisPointer: {
  275. type: 'cross'
  276. }
  277. },
  278. dataZoom: [{
  279. type: 'slider',
  280. start: 50,
  281. end: 70
  282. }, {
  283. type: 'inside',
  284. start: 50,
  285. end: 70
  286. }],
  287. xAxis: {},
  288. yAxis: {},
  289. series: [{
  290. type: 'scatter',
  291. data: data,
  292. encode: {
  293. x: 2,
  294. y: 1,
  295. label: 4
  296. },
  297. itemStyle: {
  298. normal: {
  299. color: '#77bef7'
  300. }
  301. },
  302. label: {
  303. normal: {
  304. show: true,
  305. position: 'top',
  306. textStyle: {
  307. color: '#333'
  308. }
  309. }
  310. }
  311. }]
  312. };
  313. testHelper.createChart(echarts, 'dimXY', option);
  314. });
  315. </script>
  316. </body>
  317. </html>