layout_chartview.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <div class="layui-row layui-col-space16">
  2. <div class="layui-col-md12">
  3. <div class="layui-card">
  4. <div id="chartView" style="width: 100%;height:300px;"></div>
  5. </div>
  6. </div>
  7. </div>
  8. <script>
  9. var chartView;
  10. function layoutChartView() {
  11. chartView = echarts.init(document.getElementById('chartView'));
  12. $.ajax({
  13. url: "/home/api/get_last_data",
  14. type: 'get',
  15. data: {},
  16. success: function (e) {
  17. if (e.code == 0) {
  18. var data_first = e.data.data_first;
  19. var data_second = e.data.data_second;
  20. var myDate = new Date();
  21. var nowHour = myDate.getHours(); //获取当前小时数(0-23)
  22. var xData = [];
  23. var yData1 = [];
  24. var yData2 = [];
  25. $.each(data_first, function (key, value) {
  26. if (key <= nowHour) {
  27. yData1.push(value);
  28. }
  29. });
  30. $.each(data_second, function (key, value) {
  31. xData.push(setHour(key));
  32. yData2.push(value);
  33. });
  34. var ops = {
  35. title: {
  36. top: '12px',
  37. text: '今日与昨日员工活跃度',
  38. left: '6px',
  39. textStyle: {
  40. fontSize: '18',
  41. color: '#333',
  42. }
  43. },
  44. color: ["#1AAD19", "#1890FF"],
  45. grid: {
  46. left: '16px',
  47. right: '30px',
  48. bottom: '12px',
  49. top: '60px',
  50. containLabel: true
  51. },
  52. tooltip: {
  53. trigger: 'axis',
  54. axisPointer: {
  55. type: 'cross',
  56. crossStyle: {
  57. color: '#999'
  58. }
  59. }
  60. },
  61. toolbox: {
  62. show: true,
  63. },
  64. legend: {
  65. data: ["今日", "昨日"],
  66. top: '16px',
  67. },
  68. xAxis: [{
  69. type: "category",
  70. boundaryGap: !1,
  71. data: xData,
  72. axisLine: {
  73. lineStyle: {
  74. color: '#999999',
  75. width: 1,
  76. }
  77. },
  78. }],
  79. yAxis: [{
  80. type: "value",
  81. axisLine: {
  82. show: true,
  83. lineStyle: {
  84. color: '#999999',
  85. width: 1,
  86. }
  87. },
  88. }],
  89. series: [{
  90. name: "今日",
  91. type: "line",
  92. smooth: !0,
  93. itemStyle: {
  94. normal: {
  95. areaStyle: {
  96. type: "default",
  97. opacity: 0.2
  98. }
  99. }
  100. },
  101. data: yData1
  102. }, {
  103. name: "昨日",
  104. type: "line",
  105. smooth: !0,
  106. itemStyle: {
  107. normal: {
  108. areaStyle: {
  109. type: "default",
  110. opacity: 0.2
  111. }
  112. }
  113. },
  114. data: yData2
  115. }]
  116. }
  117. chartView.setOption(ops);
  118. }
  119. }
  120. })
  121. }
  122. </script>