column.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view class="qiun-columns">
  3. <view class="qiun-bg-white qiun-title-bar qiun-common-mt" >
  4. <view class="qiun-title-dot-light">基本柱状图</view>
  5. </view>
  6. <view class="qiun-charts" style="background-color: #E5FDC3;">
  7. <!--#ifdef MP-ALIPAY -->
  8. <canvas canvas-id="canvasColumn" id="canvasColumn" class="charts" style="background-color: #E5FDC3;" :style="{'width':cWidth*pixelRatio+'px','height':cHeight*pixelRatio+'px', 'transform': 'scale('+(1/pixelRatio)+')','margin-left':-cWidth*(pixelRatio-1)/2+'px','margin-top':-cHeight*(pixelRatio-1)/2+'px'}"></canvas>
  9. <!--#endif-->
  10. <!--#ifndef MP-ALIPAY -->
  11. <canvas canvas-id="canvasColumn" id="canvasColumn" class="charts" style="background-color: #E5FDC3;"></canvas>
  12. <!--#endif-->
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import { mapState, mapActions, mapMutations } from 'vuex';
  18. import uCharts from '@/components/u-charts/u-charts.js';
  19. var _self;
  20. var canvaColumn=null;
  21. /*下面是服务器返回的数据格式*/
  22. /* var Data={
  23. Column:{categories:['2012', '2013', '2014', '2015', '2016', '2017'],
  24. series:[
  25. {
  26. name: '成交量1',
  27. data:[15, {value:20,color:'#f04864'},45, 37, 43, 34],
  28. },
  29. {
  30. name: '成交量2',
  31. data:[30, {value:40,color:'#facc14'}, 25, 14, 34, 18],
  32. }]}
  33. } */
  34. export default {
  35. data() {
  36. return {
  37. cWidth:'',
  38. cHeight:'',
  39. pixelRatio:1,
  40. serverData:'',
  41. }
  42. },
  43. computed: {
  44. ...mapState(['loginUser']),
  45. ...mapState('chart',['column']),
  46. },
  47. onLoad() {
  48. console.log(this.loginUser)
  49. _self = this;
  50. this.cWidth=uni.upx2px(750);
  51. this.cHeight=uni.upx2px(500);
  52. // this.showColumn("canvasColumn",Data.Column);
  53. this.getProductSaleMonth(this.loginUser['id'])
  54. .then(_ => [uni.stopPullDownRefresh(),this.showColumn("canvasColumn",this.column)], _ => void uni.stopPullDownRefresh());
  55. },
  56. methods: {
  57. ...mapActions('chart', ['getProductSaleMonth']),
  58. showColumn(canvasId,chartData){
  59. canvaColumn=new uCharts({
  60. $this:_self,
  61. canvasId: canvasId,
  62. enableScroll:true,
  63. type: 'column',
  64. legend:true,
  65. fontSize:11,
  66. background:'#E5FDC3',
  67. pixelRatio:_self.pixelRatio,
  68. animation: true,
  69. categories: chartData.categories,
  70. series: chartData.series,
  71. xAxis: {
  72. scrollShow:true,
  73. itemCount:8,
  74. disableGrid:true,
  75. },
  76. yAxis: {
  77. //disabled:true
  78. },
  79. dataLabel: true,
  80. width: _self.cWidth*_self.pixelRatio,
  81. height: _self.cHeight*_self.pixelRatio,
  82. extra: {
  83. column: {
  84. // width: _self.cWidth*_self.pixelRatio*0.45/chartData.categories.length
  85. width:30
  86. }
  87. }
  88. });
  89. },
  90. touchColumn(e){
  91. canvaColumn.showToolTip(e, {
  92. format: function (item, category) {
  93. if(typeof item.data === 'object'){
  94. return category + ' ' + item.name + ':' + item.data.value
  95. }else{
  96. return category + ' ' + item.name + ':' + item.data
  97. }
  98. }
  99. });
  100. },
  101. }
  102. }
  103. </script>
  104. <style>
  105. page{background:#F2F2F2;width: 750upx;overflow-x: hidden;}
  106. .qiun-padding{padding:2%; width:96%;}
  107. .qiun-wrap{display:flex; flex-wrap:wrap;}
  108. .qiun-rows{display:flex; flex-direction:row !important;}
  109. .qiun-columns{display:flex; flex-direction:column !important;}
  110. .qiun-common-mt{margin-top:10upx;}
  111. .qiun-bg-white{background:#FFFFFF;}
  112. .qiun-title-bar{width:96%; padding:10upx 2%; flex-wrap:nowrap;}
  113. .qiun-title-dot-light{border-left: 10upx solid #0ea391; padding-left: 10upx; font-size: 32upx;color: #000000}
  114. .qiun-charts{width: 750upx; height:500upx;background-color: #FFFFFF;}
  115. .charts{width: 750upx; height:500upx;background-color: #FFFFFF;}
  116. </style>