bizcharts https://bizcharts.net/product/BizCharts4/demo/390

    image.pngimage.pngimage.png

    1. import React, { useState } from 'react';
    2. import { number } from 'prop-types';
    3. import { Chart, Axis, Coordinate, Annotation, Point, registerShape } from 'bizcharts';
    4. // 自定义Shape 部分
    5. registerShape('point', 'pointer', {
    6. draw(cfg, container) {
    7. const group = container.addGroup();
    8. const center = this.parsePoint({ // 获取极坐标系下画布中心点
    9. x: 0,
    10. y: 0,
    11. });
    12. // 绘制指针
    13. group.addShape('line', {
    14. attrs: {
    15. x1: center.x,
    16. y1: center.y,
    17. x2: cfg.x,
    18. y2: cfg.y,
    19. stroke: cfg.color,
    20. lineWidth: 5,
    21. lineCap: 'round',
    22. },
    23. });
    24. group.addShape('circle', {
    25. attrs: {
    26. x: center.x,
    27. y: center.y,
    28. r: 12,
    29. stroke: cfg.color,
    30. lineWidth: 4.5,
    31. fill: '#fff',
    32. },
    33. });
    34. return group;
    35. },
    36. });
    37. const color = ['#0086FA', '#FFBF00', '#F5222D'];
    38. GaugeChart.propTypes = {
    39. value: number,
    40. };
    41. // 仪表盘图
    42. function GaugeChart({ value }) {
    43. const [state, setState] = useState({ data: [{ value: 9.6 }], lineWidth: 12 });
    44. const val = state.data[0].value;
    45. return (
    46. <Chart
    47. height={220}
    48. data={state.data}
    49. scale={{
    50. value: {
    51. min: 0,
    52. max: 9,
    53. tickInterval: 1,
    54. },
    55. }}
    56. padding={[0, 0, 30, 0]}
    57. autoFit
    58. >
    59. <Coordinate
    60. type='polar'
    61. startAngle={-9 / 8 * Math.PI}
    62. endAngle={1 / 8 * Math.PI}
    63. radius={0.75}
    64. />
    65. <Axis
    66. name='value'
    67. line={null}
    68. label={{
    69. offset: -36,
    70. textStyle: {
    71. fontSize: 18,
    72. fill: '#CBCBCB',
    73. textAlign: 'center',
    74. textBaseline: 'middle',
    75. },
    76. }}
    77. tickLine={{
    78. length: -24,
    79. stroke: '#fff',
    80. strokeOpacity: 1,
    81. }}
    82. subTickLine={{
    83. count: 4,
    84. length: -15,
    85. }}
    86. grid={null}
    87. />
    88. <Point
    89. position='value*1'
    90. color='#1890FF'
    91. shape='pointer'
    92. animate={{
    93. appear: {
    94. animation: 'fade-in',
    95. },
    96. }}
    97. />
    98. <Annotation.Arc
    99. start={[0, 0.965]}
    100. end={[6, 0.965]}
    101. style={{ // 底灰色
    102. stroke: 'rgba(0, 0, 0, 0.09)',
    103. lineWidth: state.lineWidth,
    104. }}
    105. />
    106. {val >= 2 &&
    107. <Annotation.Arc
    108. zIndex={1}
    109. start={[0, 0.965]}
    110. end={[val, 0.965]}
    111. style={{ // 底灰色
    112. stroke: color[0],
    113. lineWidth: state.lineWidth,
    114. }}
    115. />}
    116. {val >= 4 &&
    117. <Annotation.Arc
    118. zIndex={1}
    119. start={[2, 0.965]}
    120. end={[4, 0.965]}
    121. style={{ // 底灰色
    122. stroke: color[1],
    123. lineWidth: state.lineWidth,
    124. }}
    125. />}
    126. {val >= 4 && val < 6 &&
    127. <Annotation.Arc
    128. zIndex={1}
    129. start={[4, 0.965]}
    130. end={[val, 0.965]}
    131. style={{ // 底灰色
    132. stroke: color[2],
    133. lineWidth: state.lineWidth,
    134. }}
    135. />}
    136. {val >= 2 && val < 4 &&
    137. <Annotation.Arc
    138. zIndex={1}
    139. start={[2, 0.965]}
    140. end={[val, 0.965]}
    141. style={{ // 底灰色
    142. stroke: color[1],
    143. lineWidth: state.lineWidth,
    144. }}
    145. />}
    146. {val < 2 &&
    147. <Annotation.Arc
    148. zIndex={1}
    149. start={[0, 0.965]}
    150. end={[val, 0.965]}
    151. style={{ // 底灰色
    152. stroke: color[0],
    153. lineWidth: state.lineWidth,
    154. }}
    155. />}
    156. <Annotation.Text
    157. position={['50%', '85%']}
    158. content='合格率'
    159. style={{
    160. fontSize: 20,
    161. fill: '#545454',
    162. textAlign: 'center',
    163. }}
    164. />
    165. <Annotation.Text
    166. position={['50%', '90%']}
    167. content={`${val * 10} %`}
    168. style={{
    169. fontSize: 36,
    170. fill: '#545454',
    171. textAlign: 'center',
    172. }}
    173. offsetY={15}
    174. />
    175. </Chart>
    176. );
    177. }
    178. export default GaugeChart;

    antd charts https://charts.ant.design/zh-CN/demos/gauge#%E4%BB%AA%E8%A1%A8%E7%9B%98
    antv-g2Plot https://antv-g2plot.gitee.io/zh/examples/progress-plots/gauge#basic