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

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