mchart.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <view class="content">
  3. <scroll-view scroll-x="true" class="box" v-if="istrue">
  4. <view class="tu" :style="{'width': boxwidth}">
  5. <qiun-data-charts type="area" :chart-data="chartData" echartsApp />
  6. </view>
  7. </scroll-view>
  8. </view>
  9. </template>
  10. <script>
  11. import { lalaprice } from '@/api/wallet.js';
  12. export default {
  13. data() {
  14. return {
  15. boxwidth:'',
  16. istrue: false,
  17. chartData: {
  18. categories: [],
  19. series: [
  20. {
  21. name: 'LALA价格走势图',
  22. data: []
  23. }
  24. ]
  25. }
  26. };
  27. },
  28. mounted() {
  29. console.log(this.chartData, '渲染完毕');
  30. this.createChart();
  31. },
  32. methods: {
  33. createChart() {
  34. lalaprice()
  35. .then(e => {
  36. console.log(e.data, '123456');
  37. this.chart_data = e.data
  38. this.boxwidth = e.data.length *150 + 'rpx';
  39. // this.$set(this,'boxwidth',e.data.length *150 + 'rpx')
  40. console.log(this.boxwidth,"宽度")
  41. let time = e.data.map(item => {
  42. return item.date;
  43. });
  44. console.log(time);
  45. this.$set(this.chartData, 'categories', time.reverse());
  46. let val = e.data.map(item => {
  47. return +item.lala_price;
  48. });
  49. console.log(val);
  50. this.$set(this.chartData.series[0], 'data', val.reverse());
  51. this.istrue = true;
  52. })
  53. .catch(E => {
  54. console.log(E);
  55. });
  56. }
  57. }
  58. };
  59. </script>
  60. <style lang="scss" scoped>
  61. .content {
  62. width: 750rpx;
  63. height: 500rpx;
  64. }
  65. .line-chart {
  66. height: 500rpx;
  67. width: 730rpx;
  68. margin: auto;
  69. background-color: #eee;
  70. }
  71. .box {
  72. height: 500rpx;
  73. }
  74. .tu {
  75. height: 500rpx;
  76. }
  77. </style>