index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <!--
  2. 描述: 滚动弧形线
  3. 作者: Jack Chen
  4. 日期: 2020-04-20
  5. -->
  6. <template>
  7. <div class="wrap-container sn-container">
  8. <div class="sn-content">
  9. <div class="sn-title">滚动弧形线</div>
  10. <div class="sn-body">
  11. <div class="wrap-container">
  12. <div class="chartsdom" id="chart_arc"></div>
  13. </div>
  14. </div>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. export default {
  20. name: "scrollArc",
  21. data() {
  22. return {
  23. option: null,
  24. number: 0, // 播放所在下标
  25. timer: null,
  26. xData: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
  27. data: [54, 86, 46, 77, 96, 89, 88, 23, 38, 3, 66, 98]
  28. }
  29. },
  30. mounted() {
  31. this.getEchart();
  32. },
  33. methods: {
  34. getEchart() {
  35. let myChart = echarts.init(document.getElementById('chart_arc'));
  36. this.option = {
  37. tooltip: {
  38. trigger: 'axis',
  39. axisPointer: {
  40. type: 'shadow',
  41. shadowStyle: {
  42. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  43. offset: 1,
  44. color: '#5d83ff'
  45. },{
  46. offset: 0,
  47. color: 'rgba(255, 255, 255, 0)'
  48. }])
  49. }
  50. },
  51. },
  52. color: ['#5d83ff'],
  53. grid: {
  54. top: 20,
  55. left: 20,
  56. right: 20,
  57. bottom: 20,
  58. containLabel: true //轴上的数值
  59. },
  60. xAxis: {
  61. type: 'category',
  62. data: this.xData,
  63. axisTick: {
  64. show: false
  65. },
  66. axisLabel: {
  67. formatter: '{value} 月'
  68. },
  69. axisLine: {
  70. lineStyle: {
  71. color: '#999',
  72. }
  73. },
  74. },
  75. yAxis: {
  76. type: 'value',
  77. axisLine: {
  78. show: false,
  79. lineStyle: {
  80. color: '#999'
  81. }
  82. },
  83. },
  84. series: [{
  85. name: '人数',
  86. type: 'line',
  87. data: this.data,
  88. areaStyle: {
  89. normal: {
  90. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  91. offset: 0,
  92. color: '#5d83ff'
  93. },{
  94. offset: 1,
  95. color: 'rgba(0, 0, 0, 0)'
  96. }]),
  97. }
  98. },
  99. smooth: true,
  100. }]
  101. };
  102. myChart.setOption(this.option, true);
  103. window.addEventListener('resize', () => {
  104. myChart.resize();
  105. });
  106. this.timer = setInterval(() => {
  107. myChart.dispatchAction({
  108. type: 'showTip',
  109. seriesIndex: 0,
  110. dataIndex: this.number
  111. });
  112. this.number++;
  113. if (this.number > this.data.length) {
  114. this.number = 0;
  115. }
  116. }, 1000);
  117. }
  118. },
  119. beforeDestroy() {
  120. clearInterval(this.timer);
  121. }
  122. };
  123. </script>
  124. <style lang="scss" scoped>
  125. .sn-container {
  126. left: 50px;
  127. top: 690px;
  128. width: 895px;
  129. height: 400px;
  130. .chartsdom {
  131. width: 100%;
  132. height: 95%;
  133. }
  134. }
  135. </style>