DashChartDemo.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <div :style="{ padding: '0 0 32px 32px' }">
  3. <v-chart :forceFit="true" :height="300" :data="chartData" :scale="scale">
  4. <v-coord type="polar" :startAngle="-202.5" :endAngle="22.5" :radius="0.75"></v-coord>
  5. <v-axis
  6. dataKey="value"
  7. :zIndex="2"
  8. :line="null"
  9. :label="axisLabel"
  10. :subTickCount="4"
  11. :subTickLine="axisSubTickLine"
  12. :tickLine="axisTickLine"
  13. :grid="null"
  14. ></v-axis>
  15. <v-axis dataKey="1" :show="false"></v-axis>
  16. <v-series
  17. gemo="point"
  18. position="value*1"
  19. shape="pointer"
  20. color="#1890FF"
  21. :active="false"
  22. ></v-series>
  23. <v-guide
  24. type="arc"
  25. :zIndex="0"
  26. :top="false"
  27. :start="arcGuide1Start"
  28. :end="arcGuide1End"
  29. :vStyle="arcGuide1Style"
  30. ></v-guide>
  31. <v-guide
  32. type="arc"
  33. :zIndex="1"
  34. :start="arcGuide2Start"
  35. :end="getArcGuide2End"
  36. :vStyle="arcGuide2Style"
  37. ></v-guide>
  38. <v-guide
  39. type="html"
  40. :position="htmlGuidePosition"
  41. :html="getHtmlGuideHtml()"
  42. ></v-guide>
  43. </v-chart>
  44. </div>
  45. </template>
  46. <script>
  47. import { registerShape } from 'viser-vue';
  48. registerShape('point', 'pointer', {
  49. draw(cfg, container) {
  50. let point = cfg.points[0];
  51. point = this.parsePoint(point);
  52. const center = this.parsePoint({
  53. x: 0,
  54. y: 0,
  55. });
  56. container.addShape('line', {
  57. attrs: {
  58. x1: center.x,
  59. y1: center.y,
  60. x2: point.x,
  61. y2: point.y + 15,
  62. stroke: cfg.color,
  63. lineWidth: 5,
  64. lineCap: 'round',
  65. }
  66. });
  67. return container.addShape('circle', {
  68. attrs: {
  69. x: center.x,
  70. y: center.y,
  71. r: 9.75,
  72. stroke: cfg.color,
  73. lineWidth: 4.5,
  74. fill: '#fff',
  75. }
  76. });
  77. }
  78. });
  79. const scale = [{
  80. dataKey: 'value',
  81. min: 0,
  82. max: 9,
  83. tickInterval: 1,
  84. nice: false,
  85. }];
  86. const data = [
  87. { value: 7.0 },
  88. ];
  89. export default {
  90. name:"DashChartDemo",
  91. props:{
  92. datasource:{
  93. type: Number,
  94. default:7
  95. },
  96. title: {
  97. type: String,
  98. default: ''
  99. }
  100. },
  101. created(){
  102. if(!this.datasource){
  103. this.chartData = data;
  104. }else{
  105. this.chartData = [
  106. { value: this.datasource },
  107. ];
  108. }
  109. this.getChartData()
  110. },
  111. watch: {
  112. 'datasource': function (val) {
  113. this.chartData = [
  114. { value: val},
  115. ];
  116. this.getChartData();
  117. }
  118. },
  119. methods:{
  120. getChartData(){
  121. if(this.chartData && this.chartData.length>0){
  122. this.abcd = this.chartData[0].value * 10
  123. }else{
  124. this.abcd = 70
  125. }
  126. },
  127. getHtmlGuideHtml(){
  128. return '<div style="width: 300px;text-align: center;">\n' +
  129. '<p style="font-size: 14px;color: #545454;margin: 0;">'+this.title+'</p>\n' +
  130. '<p style="font-size: 36px;color: #545454;margin: 0;">'+this.abcd+'%</p>\n' +
  131. '</div>'
  132. },
  133. getArcGuide2End(){
  134. return [this.chartData[0].value, 0.945]
  135. }
  136. },
  137. data() {
  138. return {
  139. chartData:[],
  140. height: 400,
  141. scale: scale,
  142. abcd:70,
  143. axisLabel: {
  144. offset: -16,
  145. textStyle: {
  146. fontSize: 18,
  147. textAlign: 'center',
  148. textBaseline: 'middle'
  149. }
  150. },
  151. axisSubTickLine: {
  152. length: -8,
  153. stroke: '#fff',
  154. strokeOpacity: 1,
  155. },
  156. axisTickLine: {
  157. length: -17,
  158. stroke: '#fff',
  159. strokeOpacity: 1,
  160. },
  161. arcGuide1Start: [0, 0.945],
  162. arcGuide1End: [9, 0.945],
  163. arcGuide1Style: {
  164. stroke: '#CBCBCB',
  165. lineWidth: 18,
  166. },
  167. arcGuide2Start: [0, 0.945],
  168. arcGuide2Style: {
  169. stroke: '#1890FF',
  170. lineWidth: 18,
  171. },
  172. htmlGuidePosition: ['50%', '100%'],
  173. htmlGuideHtml: `
  174. <div style="width: 300px;text-align: center;">
  175. <p style="font-size: 14px;color: #545454;margin: 0;">${this.title}</p>
  176. <p style="font-size: 36px;color: #545454;margin: 0;">${this.abcd}%</p>
  177. </div>
  178. `,
  179. };
  180. },
  181. };
  182. </script>