hard.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <div id="hard" style="width: 140px;height: 280px;"></div>
  3. </template>
  4. <script >
  5. // var showValue = new Array()
  6. var showValue = [7,-6,7,6,7,-6,7,6,7,-6,7,6];
  7. const colors = ['#5470C6', '#91CC75', '#EE6666'];
  8. export default {
  9. data(){
  10. return {
  11. chartInstance: null,
  12. allData:null, // 服务器返回的数据
  13. currentPage: 1, //当前显示的页数, 当修改页数时, 数据动态刷新
  14. totalPage: 0, //一共多少也
  15. timerId:null //定时器
  16. }
  17. },
  18. mounted(){
  19. this.initChart() //函数调用
  20. this.updateChart()
  21. // 对窗口大小变化的事件进行监听
  22. // window.addEventListener('resize', this.screenAdapter)
  23. },
  24. // Vue生命周期 - 销毁时
  25. // destroyed () {
  26. // clearInterval(this.timerId)
  27. // // 在组件销毁的时候, 需要将监听器取消掉
  28. // // window.removeEventListener('resize', this.screenAdapter)
  29. // },
  30. methods:{
  31. initChart(){
  32. this.chartInstance = this.$echarts.init(document.getElementById('hard'))
  33. //对图表对象进行鼠标事件监听
  34. this.chartInstance.on('mousecver', () =>{
  35. this.clearInterval(this.timerId)
  36. })
  37. this.chartInstance.on('mouseout', () => {
  38. this.startInterval()
  39. })
  40. },
  41. // async getData () {
  42. // // 请求数据
  43. // const { data: ret } = await this.$http.get('hbase/getJSON')
  44. // const { data1:ret1 } = await this.$http.get('engine/start/?mode=mode3')
  45. // this.allData = ret
  46. // // 对数据排序
  47. // this.allData.sort((a,b) => {{
  48. // return a.value-b.value //从小到大排序
  49. // }})
  50. // // 每1个元素显示一页
  51. // this.totalPage = this.allData.length % 1 ===0 ? this.allData.length /1 : this.allData.length / 1 +1
  52. // // 获取完数据, 更新图标
  53. // this.updateChart()
  54. // // // 启动定时器, 每隔三秒改变currentPage, 进而更新图表
  55. // this.startInterval()
  56. // },
  57. updateChart(){
  58. // 每一页显示1个数据, 获取1个数据
  59. // const start = (this.currentPage - 1) * 1
  60. // const end = this.currentPage * 1
  61. // const showData = this.allData.slice(start, end)
  62. // const tempDate = showData[0].gejieguiji
  63. // showValue.push(tempDate)
  64. // if(showValue.length>=12){
  65. // for(let i=1; i<=showValue.length; i++){
  66. // showValue.pop()
  67. // }
  68. // }
  69. // const testData = [7,-6,7,6,7,-6,7,6,7,-6,7,6]
  70. var option = {
  71. // title: {
  72. // text: '行走状态',
  73. // show: true
  74. // },
  75. color: colors,
  76. tooltip: {
  77. trigger: 'axis',
  78. axisPointer: {
  79. type: 'cross'
  80. }
  81. },
  82. grid: {
  83. right: '10%',
  84. show:'false'
  85. // color:'red'
  86. },
  87. xAxis: [
  88. {
  89. // offset:0,
  90. type: 'category',
  91. axisLine:{
  92. show:true
  93. },
  94. axisLabel:{
  95. show:false
  96. },
  97. axisTick:{
  98. show:false
  99. },
  100. // prettier-ignore
  101. data: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  102. },
  103. // {
  104. // offset: -100,
  105. // axisLine:{
  106. // show:true,
  107. // lineStyle:{
  108. // color:'red',
  109. // type:'dashed'
  110. // }
  111. // },
  112. // },
  113. // {
  114. // offset: -80,
  115. // axisLine:{
  116. // show:true,
  117. // lineStyle:{
  118. // color:'red',
  119. // type:'dashed'
  120. // }
  121. // }
  122. // }
  123. ],
  124. yAxis: [
  125. {
  126. type: 'value',
  127. min: -10,
  128. max: 10,
  129. position: 'right',
  130. offset:0,
  131. axisLine:{
  132. show:true,
  133. lineStyle:{
  134. color:'blue',
  135. }
  136. },
  137. axisLabel:{
  138. show:false
  139. },
  140. axisTick:{
  141. show:false
  142. },
  143. },
  144. {
  145. type: 'value',
  146. min: -10,
  147. max: 10,
  148. position: 'left',
  149. axisLine:{
  150. show:true,
  151. lineStyle:{
  152. color:'blue',
  153. }
  154. },
  155. axisLabel:{
  156. show:false
  157. },
  158. axisTick:{
  159. show:false
  160. },
  161. },
  162. {
  163. type: 'value',
  164. name: '1',
  165. min: 0,
  166. max: 25,
  167. offset:-200,
  168. position: 'left',
  169. axisLine:{
  170. show:true,
  171. lineStyle:{
  172. color:'blue',
  173. }
  174. },
  175. axisLabel:{
  176. show:false
  177. },
  178. axisTick:{
  179. show:false
  180. },
  181. },
  182. {
  183. type: 'value',
  184. name: '2',
  185. min: 0,
  186. max: 25,
  187. offset:-200,
  188. position: 'right',
  189. axisLine:{
  190. show:true,
  191. lineStyle:{
  192. color:'blue',
  193. }
  194. },
  195. axisLabel:{
  196. show:false
  197. },
  198. axisTick:{
  199. show:false
  200. },
  201. }
  202. ],
  203. series: [
  204. {
  205. type: 'line',
  206. data: showValue,
  207. symbol: 'triangle',
  208. symbolSize: 20,
  209. lineStyle: {
  210. color: '#5470C6',
  211. width: 4,
  212. type: 'dashed'
  213. },
  214. itemStyle: {
  215. borderWidth: 3,
  216. borderColor: '#EE6666',
  217. color: 'yellow'
  218. },
  219. areaStyle:{}
  220. }
  221. ]
  222. };
  223. this.chartInstance.setOption(option)
  224. // 启动定时器, 每隔三秒改变currentPage, 进而更新图表
  225. // this.startInterval()
  226. },
  227. // startInterval () {
  228. // // 每个3秒执行一次
  229. // setInterval(() => {
  230. // // 保险操作
  231. // if(this.timeId){
  232. // clearInterval(this.timerId)
  233. // }
  234. // this.currentPage++
  235. // // 当页数超过总页数是, 从头开始
  236. // if(this.currentPage > this.totalPage){
  237. // this.currentPage = 1
  238. // }
  239. // //this.getData()
  240. // this.updateChart()
  241. // },3000)
  242. // }
  243. }
  244. }
  245. </script>
  246. <style scoped>
  247. </style>