p-production-statistics-section-1.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <view>
  3. <canvas canvas-id="canvasRing" id="canvasRing" @touchstart="touchRing" style="width: 700upx; height:500upx;" ></canvas>
  4. </view>
  5. </template>
  6. <script>
  7. import uCharts from '@/components/u-charts/u-charts.js';
  8. var _self;
  9. var canvaRing = null;
  10. export default {
  11. data() {
  12. return {
  13. cWidth: '',
  14. cHeight: '',
  15. pixelRatio: 1,
  16. serverData: '',
  17. }
  18. },
  19. mounted() {
  20. _self = this;
  21. this.cWidth = uni.upx2px(700);
  22. this.cHeight = uni.upx2px(500);
  23. this.getServerData();
  24. },
  25. methods: {
  26. getServerData() {
  27. let Ring = {
  28. "series": [{
  29. "name": "早班 63950.8 吨",
  30. "data": 63950.8
  31. }, {
  32. "name": "中班 5860.8 吨",
  33. "data": 5860.8
  34. }, {
  35. "name": "晚班 0 吨",
  36. "data": 0
  37. }]
  38. };
  39. _self.showRing("canvasRing", Ring);
  40. },
  41. showRing(canvasId, chartData) {
  42. canvaRing = new uCharts({
  43. $this: _self,
  44. canvasId: canvasId,
  45. type: 'ring',
  46. fontSize: 11,
  47. legend: {
  48. show: true,
  49. position: 'left',
  50. lineHeight: 40,
  51. },
  52. title: {
  53. name: '69811.6吨',
  54. color: '#000000',
  55. fontSize: 20 * _self.pixelRatio,
  56. offsetY: 20 * _self.pixelRatio,
  57. },
  58. subtitle: {
  59. name: '总产量',
  60. color: '#666666',
  61. fontSize: 14 * _self.pixelRatio,
  62. offsetY: -30 * _self.pixelRatio,
  63. },
  64. extra: {
  65. pie: {
  66. offsetAngle: -90,
  67. ringWidth: 20 * _self.pixelRatio,
  68. labelWidth: 15
  69. }
  70. },
  71. background: '#FFFFFF',
  72. pixelRatio: _self.pixelRatio,
  73. series: chartData.series,
  74. animation: true,
  75. width: _self.cWidth * _self.pixelRatio,
  76. height: _self.cHeight * _self.pixelRatio,
  77. disablePieStroke: true,
  78. dataLabel: false,
  79. });
  80. },
  81. touchRing(e) {
  82. canvaRing.showToolTip(e, {
  83. format: function(item) {
  84. // return item.name + ' : ' + item.data + ' 吨'
  85. return item.name
  86. }
  87. });
  88. },
  89. }
  90. }
  91. </script>
  92. <style>
  93. </style>