test2.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <div id="test2">
  3. <div class="timeQuery" style="width: 100%; height: 300px" id="timeQuery">
  4. </div>
  5. </div>
  6. </template>
  7. <script>
  8. import * as echarts from 'echarts';
  9. export default {
  10. name: "test2",
  11. data() {
  12. return {
  13. };
  14. },
  15. mounted() {
  16. var base = +new Date("2021-02-02 00:00:00");
  17. var oneDay = 24 * 3600 * 1000;
  18. var data = [[base, 10]];
  19. for (var i = 1; i < 24; i++) {
  20. var now = new Date(base += oneDay);
  21. data.push([
  22. new Date("2021-02-02 " + i+":00:00"), 10
  23. ]);
  24. }
  25. // 基于准备好的dom,初始化echarts实例
  26. var myChart = echarts.init(document.getElementById('timeQuery'));
  27. let option = {
  28. toolbox: {
  29. feature: {
  30. dataZoom: {
  31. yAxisIndex: 'none'
  32. },
  33. restore: {},
  34. saveAsImage: {}
  35. }
  36. },
  37. xAxis: {
  38. type: 'time',
  39. boundaryGap: false
  40. },
  41. yAxis: {
  42. type: 'value',
  43. show: false,
  44. splitLine:{show: false}, //去除网格线
  45. boundaryGap: [0, '100%']
  46. },
  47. dataZoom: [{
  48. type: 'inside',
  49. start: 0,
  50. end: 20
  51. }, {
  52. start: 0,
  53. end: 20
  54. }],
  55. series: [
  56. {
  57. name: '模拟数据',
  58. type: 'line',
  59. smooth: false,
  60. symbol: 'none',
  61. areaStyle: {},
  62. data: data
  63. }
  64. ]
  65. };
  66. // 绘制图表
  67. myChart.setOption(option);
  68. },
  69. methods:{
  70. getTimeNode(){
  71. let mine = 20
  72. let width = document.getElementById("timeQuery").offsetWidth
  73. if (width/20 > 24){
  74. return 24
  75. }else if (width/20 > 12) {
  76. return 12
  77. }else if (width/20 > 6) {
  78. return 6
  79. }
  80. },
  81. hoveEvent(event){
  82. console.log(2222222)
  83. console.log(event)
  84. },
  85. timeChoose(event){
  86. console.log(event)
  87. },
  88. getDataWidth(item){
  89. let startTime = new Date(item.startTime);
  90. let endTime = new Date(item.endTime);
  91. let result = parseFloat((endTime.getTime() - startTime.getTime())/(24*60*60*10))
  92. // console.log(result)
  93. return parseFloat((endTime.getTime() - startTime.getTime())/(24*60*60*10))
  94. },
  95. getDataLeft(item){
  96. let startTime = new Date(item.startTime);
  97. let differenceTime = startTime.getTime() - new Date(item.startTime.substr(0,10) + " 00:00:00").getTime()
  98. let result = differenceTime/(24*60*60*10)
  99. console.log(differenceTime)
  100. console.log(result)
  101. return parseFloat(differenceTime/(24*60*60*10));
  102. }
  103. }
  104. }
  105. </script>
  106. <style scoped>
  107. .timeQuery{
  108. width: 96%;
  109. margin-left: 2%;
  110. margin-right: 2%;
  111. margin-top: 20%;
  112. position: absolute;
  113. }
  114. .timeQuery-background{
  115. height: 16px;
  116. width: 100%;
  117. background-color: #ececec;
  118. position: absolute;
  119. left: 0;
  120. top: 0;
  121. z-index: 10;
  122. box-shadow: #9d9d9d 0px 0px 10px inset;
  123. }
  124. .timeQuery-data{
  125. height: 16px;
  126. width: 100%;
  127. position: absolute;
  128. left: 0;
  129. top: 0;
  130. z-index: 11;
  131. }
  132. .timeQuery-data-cell{
  133. height: 10px;
  134. background-color: #888787;
  135. position: absolute;
  136. z-index: 11;
  137. -webkit-box-shadow: #9d9d9d 0px 0px 10px inset;
  138. margin-top: 3px;
  139. }
  140. .timeQuery-label{
  141. height: 16px;
  142. width: 100%;
  143. position: absolute;
  144. pointer-events: none;
  145. left: 0;
  146. top: 0;
  147. z-index: 11;
  148. }
  149. .timeQuery-label-cell{
  150. height: 16px;
  151. position: absolute;
  152. z-index: 12;
  153. width: 0px;
  154. border-right: 1px solid #b7b7b7;
  155. }
  156. .timeQuery-label-cell-label {
  157. width: 23px;
  158. text-align: center;
  159. height: 18px;
  160. margin-left: -10px;
  161. margin-top: -30px;
  162. color: #444;
  163. }
  164. .timeQuery-pointer{
  165. width: 0px;
  166. height: 18px;
  167. position: absolute;
  168. left: 0;
  169. }
  170. .timeQuery-pointer-content{
  171. width: 0px;
  172. height: 16px;
  173. position: absolute;
  174. border-right: 3px solid #f60303;
  175. z-index: 14;
  176. }
  177. /*.timeQuery-cell:after{*/
  178. /* content: "";*/
  179. /* height: 14px;*/
  180. /* border: 1px solid #e70303;*/
  181. /* position: absolute;*/
  182. /*}*/
  183. </style>