ucharts-line.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view class="ucharts-line">
  3. <canvas disable-scroll=true @touchstart="touchLine" @touchmove="moveLine" @touchend="touchEndLine" :canvas-id="id" :id="id" :style="{'width':cWidth+'px','height':cHeight+'px'}"></canvas>
  4. </view>
  5. </template>
  6. <script>
  7. import uCharts from '../common/js/u-charts.js'
  8. let canvaLine = null
  9. export default {
  10. props: {
  11. chartData: Object
  12. },
  13. data() {
  14. return {
  15. id: 'ucharts-line',
  16. cWidth:'',
  17. cHeight:'',
  18. color: ['#FA6342'],
  19. total: 0
  20. }
  21. },
  22. created () {
  23. this.cWidth= uni.upx2px(568);
  24. this.cHeight= uni.upx2px(405);
  25. },
  26. mounted () {
  27. canvaLine = new uCharts({
  28. $this: this, //传入this
  29. canvasId: this.id, //传入id
  30. colors: this.color, //颜色
  31. type: 'line', //类型折线图
  32. fontSize: uni.upx2px(24), //字体大小
  33. background:'#FFFFFF', //背景色
  34. pixelRatio: 1, //像素比,默认为1,仅支付宝小程序需要大于1,其他平台必须为1
  35. animation: true, //展示动画
  36. padding: [4, 0, 0, 0],
  37. enableScroll: true,//开启图表拖拽功能
  38. categories: this.chartData.categories,
  39. series: this.chartData.series, //数据
  40. extra: {
  41. line: {
  42. type: 'curve',
  43. width: uni.upx2px(8)
  44. }
  45. },
  46. width: this.cWidth, //图表宽
  47. height: this.cHeight, //图表高
  48. legend:{ //不显示图例
  49. show: false
  50. },
  51. dataLabel: true, //显示数据
  52. dataPointShapeType: 'hollow',
  53. addPoint: true,
  54. xAxis: {
  55. disableGrid: false,
  56. type: 'grid',
  57. gridColor: '#E6E6E6',
  58. fontColor: '#666666',
  59. boundaryGap: 'justify',
  60. axisLineColor: '#0065FF',
  61. itemCount: 7,
  62. labelCount: 8,
  63. scrollShow: true,
  64. scrollAlign: 'right',
  65. scrollBackgroundColor:'#F7F7FF',//可不填写,配合enableScroll图表拖拽功能使用,X轴滚动条背景颜色,默认为 #EFEBEF
  66. scrollColor:'#FA6342',//可不填写,配合enableScroll图表拖拽功能使用,X轴滚动条颜色,默认为 #A6A6A6
  67. },
  68. yAxis: {
  69. splitNumber: 4,
  70. gridColor: '#E6E6E6',
  71. fontSize: uni.upx2px(12),
  72. min: 0,
  73. max: 40,
  74. axisLineColor: '#E6E6E6',
  75. }
  76. })
  77. },
  78. methods: {
  79. touchLine (e) {
  80. canvaLine.scrollStart(e)
  81. },
  82. moveLine (e) {
  83. canvaLine.scroll(e)
  84. },
  85. touchEndLine (e) {
  86. canvaLine.scrollEnd(e)
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. .ucharts-line {
  93. width: 100%;
  94. height: auto;
  95. }
  96. </style>