dynamicData.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. <meta name="viewport" content="width=device-width, initial-scale=1" />
  7. </head>
  8. <body>
  9. <style>
  10. html, body, #main {
  11. width: 100%;
  12. height: 100%;
  13. }
  14. </style>
  15. <div id="main"></div>
  16. <script>
  17. require([
  18. 'echarts',
  19. 'echarts/chart/line',
  20. 'echarts/component/legend',
  21. 'echarts/component/grid'
  22. ], function (echarts) {
  23. function randomData() {
  24. return (Math.random() + 3).toFixed(3);
  25. }
  26. var chart = echarts.init(document.getElementById('main'), null, {
  27. renderer: 'canvas'
  28. });
  29. var xAxisData = [];
  30. var data1 = [];
  31. var data2 = [];
  32. var count = 0;
  33. for (; count < 500; count++) {
  34. xAxisData.push('类目' + count);
  35. data1.push(randomData());
  36. // data2.push(-randomData());
  37. }
  38. var itemStyle = {
  39. normal: {
  40. borderColor: 'white',
  41. borderWidth: 3,
  42. // shadowBlur: 10,
  43. // shadowOffsetX: 0,
  44. // shadowOffsetY: 5,
  45. // shadowColor: 'rgba(0, 0, 0, 0.4)',
  46. lineStyle: {
  47. width: 2
  48. // shadowBlur: 10,
  49. // shadowOffsetX: 0,
  50. // shadowOffsetY: 5,
  51. // shadowColor: 'rgba(0, 0, 0, 0.4)'
  52. },
  53. areaStyle: {
  54. }
  55. }
  56. };
  57. chart.setOption({
  58. legend: {
  59. data: ['line', 'line2']
  60. },
  61. tooltip: {
  62. trigger: 'axis',
  63. axisPointer: {
  64. type: 'line'
  65. }
  66. },
  67. // animation: false,
  68. xAxis: {
  69. axisLabel: {
  70. interval: 40
  71. },
  72. data: xAxisData,
  73. boundaryGap: false
  74. },
  75. yAxis: {
  76. scale: true,
  77. splitLine: {
  78. // show: false
  79. }
  80. },
  81. series: [{
  82. name: 'line',
  83. type: 'line',
  84. stack: 'all',
  85. symbol: 'none',
  86. symbolSize: 10,
  87. data: data1,
  88. itemStyle: itemStyle
  89. }]
  90. });
  91. setInterval(function () {
  92. for (var i = 0; i < 5; i++) {
  93. xAxisData.shift();
  94. xAxisData.push('类目' + count);
  95. data1.shift();
  96. data1.push(randomData());
  97. count++;
  98. }
  99. chart.setOption({
  100. xAxis: {
  101. data: xAxisData
  102. },
  103. series: [{
  104. name: 'line',
  105. data: data1
  106. }]
  107. });
  108. }, 500);
  109. })
  110. </script>
  111. </body>
  112. </html>