axisLabel.html 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <!DOCTYPE>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <script src="lib/esl.js"></script>
  6. <script src="lib/config.js"></script>
  7. <script src="lib/jquery.min.js"></script>
  8. <script src="lib/facePrint.js"></script>
  9. <meta name="viewport" content="width=device-width, initial-scale=1" />
  10. <link rel="stylesheet" href="lib/reset.css">
  11. </head>
  12. <body>
  13. <style>
  14. body {
  15. background: #333;
  16. }
  17. .chart {
  18. height: 400px;
  19. }
  20. </style>
  21. <div class="chart" id="main1"></div>
  22. <div class="chart" id="main2"></div>
  23. <script>
  24. require([
  25. 'echarts'
  26. // 'zrender/tool/color',
  27. // 'echarts/chart/line',
  28. // 'echarts/chart/parallel',
  29. // 'echarts/component/title',
  30. // 'echarts/component/grid',
  31. // 'echarts/component/legend',
  32. // 'echarts/component/tooltip',
  33. // 'echarts/component/toolbox',
  34. // 'echarts/component/visualMap'
  35. ], function (echarts) {
  36. var chart = echarts.init(document.getElementById('main1'));
  37. var DECIMALS = [1];
  38. for (var i = 1; i < 15; i++) {
  39. DECIMALS.push(DECIMALS[DECIMALS.length - 1] * 10);
  40. }
  41. window.yAxisLabelFormatter = (function () {
  42. var labelMap = {};
  43. return function (val, index) {
  44. !index && (labelMap = {});
  45. if (val < 0) {
  46. return '';
  47. }
  48. var label = val >= DECIMALS[11]
  49. ? fix((val / DECIMALS[12]).toFixed(val >= DECIMALS[13] ? 0 : 1)) + 'T'
  50. : val >= DECIMALS[8]
  51. ? fix((val / DECIMALS[9]).toFixed(val >= DECIMALS[10] ? 0 : 1)) + 'B'
  52. : val >= DECIMALS[5]
  53. ? fix((val / DECIMALS[6]).toFixed(val >= DECIMALS[7] ? 0 : 1)) + 'M'
  54. : val >= DECIMALS[3]
  55. ? fix((val / DECIMALS[3]).toFixed(val >= DECIMALS[4] ? 0 : 1)) + 'K'
  56. : val;
  57. return (
  58. labelMap[label]
  59. ? ''
  60. : (labelMap[label] = true, label)
  61. ) + '\n';
  62. function fix(valStr) {
  63. return valStr.replace(/[.]0+$/, '');
  64. }
  65. };
  66. })();
  67. window.smallYAxisLabel = {
  68. show: true,
  69. margin: 2,
  70. formatter: window.yAxisLabelFormatter,
  71. inside: true,
  72. textStyle: {
  73. // color: '#f7e1a9',
  74. color: 'rgba(255,255,255,0.3)',
  75. fontSize: 9,
  76. fontFamily: 'STHeiti'
  77. }
  78. };
  79. option = {
  80. backgroundColor: '#eee',
  81. title: {
  82. text: '上两个 label 显示不出来怎么办'
  83. },
  84. grid: {
  85. backgroundColor: '#333',
  86. show: true,
  87. borderWidth: 0,
  88. height: 156,
  89. top: '15%',
  90. left: 100,
  91. right: 100
  92. },
  93. xAxis: {
  94. type: 'time'
  95. },
  96. tooltip: {
  97. trigger: 'axis'
  98. },
  99. yAxis: {
  100. type: 'value',
  101. scale: true,
  102. boundaryGap: ['3%', '3%'],
  103. splitNumber: 3,
  104. axisLine: {
  105. show: false
  106. },
  107. splitLine: {
  108. lineStyle: {
  109. type: 'solid',
  110. color: '#9f520e'
  111. }
  112. },
  113. axisTick: {
  114. show: false
  115. },
  116. axisLabel: window.smallYAxisLabel
  117. },
  118. easing: 'linear',
  119. series: [{
  120. name: '视频制作总数',
  121. type: 'line',
  122. lineStyle: {
  123. normal: {
  124. color: '#f9bb0b'
  125. }
  126. },
  127. showSymbol: false,
  128. data: [{"name":"980061360000","value":[980061360000,1519]},{"name":"980061420000","value":[980061420000,1526]},{"name":"980061480000","value":[980061480000,1530]},{"name":"980061540000","value":[980061540000,1531]},{"name":"980061600000","value":[980061600000,1531]},{"name":"980061660000","value":[980061660000,1532]},{"name":"980061720000","value":[980061720000,1532]},{"name":"980061780000","value":[980061780000,1533]},{"name":"980061840000","value":[980061840000,1533]},{"name":"980061900000","value":[980061900000,1537]},{"name":"980061960000","value":[980061960000,1537]},{"name":"980062020000","value":[980062020000,1539]},{"name":"980062080000","value":[980062080000,1552]},{"name":"980062140000","value":[980062140000,1552]},{"name":"980062200000","value":[980062200000,1559]},{"name":"980062260000","value":[980062260000,1561]},{"name":"980062320000","value":[980062320000,1562]},{"name":"980062380000","value":[980062380000,1562]},{"name":"980062440000","value":[980062440000,1562]},{"name":"980062500000","value":[980062500000,1563]},{"name":"980062560000","value":[980062560000,1563]},{"name":"980062620000","value":[980062620000,1565]},{"name":"980062680000","value":[980062680000,1569]},{"name":"980062740000","value":[980062740000,1575]},{"name":"980062800000","value":[980062800000,1579]},{"name":"980062860000","value":[980062860000,1579]},{"name":"980062920000","value":[980062920000,1581]},{"name":"980062980000","value":[980062980000,1582]},{"name":"980063040000","value":[980063040000,1585]},{"name":"980063100000","value":[980063100000,1589]},{"name":"980063160000","value":[980063160000,1590]},{"name":"980063220000","value":[980063220000,1590]},{"name":"980063280000","value":[980063280000,1591]},{"name":"980063340000","value":[980063340000,1591]},{"name":"980063400000","value":[980063400000,1592]},{"name":"980063460000","value":[980063460000,1592]},{"name":"980063520000","value":[980063520000,1593]},{"name":"980063580000","value":[980063580000,1605]},{"name":"980063640000","value":[980063640000,1609]},{"name":"980063700000","value":[980063700000,1612]},{"name":"980063760000","value":[980063760000,1614]},{"name":"980063820000","value":[980063820000,1614]},{"name":"980063880000","value":[980063880000,1617]},{"name":"980063940000","value":[980063940000,1617]},{"name":"980064000000","value":[980064000000,1619]},{"name":"980064060000","value":[980064060000,1622]},{"name":"980064120000","value":[980064120000,1622]},{"name":"980064180000","value":[980064180000,1624]},{"name":"980064240000","value":[980064240000,1627]},{"name":"980064300000","value":[980064300000,1640]},{"name":"980064360000","value":[980064360000,1642]},{"name":"980064420000","value":[980064420000,1642]},{"name":"980064480000","value":[980064480000,1643]},{"name":"980064540000","value":[980064540000,1644]},{"name":"980064600000","value":[980064600000,1644]},{"name":"980064660000","value":[980064660000,1647]},{"name":"980064720000","value":[980064720000,1647]},{"name":"980064780000","value":[980064780000,1648]},{"name":"980064840000","value":[980064840000,1648]},{"name":"980064900000","value":[980064900000,1648]}]
  129. }]
  130. };
  131. chart.setOption(option);
  132. });
  133. </script>
  134. <script>
  135. require([
  136. 'echarts'
  137. ], function (echarts) {
  138. var chart = echarts.init(document.getElementById('main2'));
  139. var rotate = 30;
  140. option = {
  141. backgroundColor: '#eee',
  142. title: {
  143. text: 'grid.containLabel'
  144. },
  145. grid: {
  146. containLabel: true,
  147. left: 0
  148. },
  149. tooltip: {
  150. trigger: 'axis'
  151. },
  152. xAxis: {
  153. data: ['a', 'b', 'c', 'd', 'e']
  154. },
  155. yAxis: {
  156. axisLabel: {
  157. rotate: rotate
  158. }
  159. },
  160. series: [{
  161. type: 'line',
  162. data: [
  163. 1111111111111,
  164. 2222222222222,
  165. 3333333333333,
  166. 4444444444444,
  167. 5555555555555,
  168. 6666666666666
  169. ]
  170. }]
  171. };
  172. chart.setOption(option);
  173. setInterval(function () {
  174. rotate = (rotate + 1) % 360;
  175. chart.setOption({
  176. yAxis: {
  177. axisLabel: {
  178. rotate: rotate
  179. }
  180. }
  181. });
  182. }, 100);
  183. });
  184. </script>
  185. </body>
  186. </html>