Line.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view class="">
  3. <view class="qiun-charts">
  4. <canvas :canvas-id="canvasId" :id="canvasId" class="charts" @touchstart="touchLineA"></canvas>
  5. </view>
  6. </view>
  7. </template>
  8. <script>
  9. import uCharts from '@/assets/js/u-charts/u-charts/u-charts.js';
  10. var _self;
  11. var canvaLineA = null;
  12. export default {
  13. data() {
  14. return {
  15. cWidth: '',
  16. cHeight: '',
  17. pixelRatio: 1,
  18. }
  19. },
  20. props: {
  21. lineJson: {
  22. type: Object,
  23. default: null
  24. },
  25. canvasId: {
  26. type: String,
  27. default: "canvasLineA"
  28. },
  29. },
  30. created() {
  31. _self = this;
  32. this.cWidth = uni.upx2px(750);
  33. this.cHeight = uni.upx2px(500);
  34. _self.showLineA(this.canvasId, this.lineJson);
  35. },
  36. methods: {
  37. showLineA(canvasId, chartData) {
  38. canvaLineA = new uCharts({
  39. $this: _self,
  40. canvasId: canvasId,
  41. type: 'line',
  42. fontSize: 11,
  43. legend: {show: true},
  44. dataLabel: false,
  45. dataPointShape: true,
  46. background: '#FFFFFF',
  47. pixelRatio: _self.pixelRatio,
  48. categories: chartData.categories,
  49. series: chartData.series,
  50. animation: true,
  51. xAxis: {
  52. type: 'grid',
  53. gridColor: '#CCCCCC',
  54. gridType: 'dash',
  55. disableGrid: true,
  56. dashLength: 8,
  57. rotateLabel: true
  58. },
  59. yAxis: {
  60. disableGrid: true,
  61. gridType: 'dash',
  62. gridColor: '#CCCCCC',
  63. dashLength: 8,
  64. splitNumber: 5,
  65. min: 10,
  66. max: 180,
  67. format: (val) => {
  68. return val.toFixed(0)
  69. }
  70. },
  71. width: _self.cWidth * _self.pixelRatio,
  72. height: _self.cHeight * _self.pixelRatio,
  73. extra: {
  74. line: {
  75. type: 'straight'
  76. }
  77. }
  78. });
  79. },
  80. touchLineA(e) {
  81. canvaLineA.showToolTip(e, {
  82. format: function (item, category) {
  83. return category + ' ' + item.name + ':' + item.data
  84. }
  85. });
  86. }
  87. }
  88. }
  89. </script>
  90. <style>
  91. .qiun-charts {
  92. width: 750 upx;
  93. height: 500 upx;
  94. background-color: #FFFFFF;
  95. }
  96. .charts {
  97. width: 750 upx;
  98. height: 500 upx;
  99. background-color: #FFFFFF;
  100. }
  101. </style>