recent-detail-chart.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <mx-echarts :option="option" canvas-id="recent-detail-chart"/>
  3. </template>
  4. <script>
  5. export default {
  6. name: "recent-detail-chart",
  7. props: {
  8. data: {
  9. type: Array,
  10. default: () => []
  11. }
  12. },
  13. data() {
  14. return {
  15. option: null
  16. }
  17. },
  18. watch: {
  19. data: function () {
  20. this.updateOption()
  21. }
  22. },
  23. mounted() {
  24. this.updateOption()
  25. },
  26. methods: {
  27. updateOption() {
  28. const xData = []
  29. const yData = []
  30. if (Array.isArray(this.data)) {
  31. this.data.forEach(i => {
  32. xData.push(i.text)
  33. yData.push(i.value)
  34. })
  35. }
  36. this.option = {
  37. color: ['#4F87FC'],
  38. xAxis: {
  39. type: 'category',
  40. data: xData
  41. },
  42. yAxis: {
  43. type: 'value'
  44. },
  45. series: [{
  46. data: yData,
  47. type: 'line',
  48. smooth: true
  49. }]
  50. };
  51. }
  52. }
  53. }
  54. </script>
  55. <style scoped>
  56. </style>