避免使用scale的formatter,会全局生效,推荐使用Geom的formatter; 文档链接
    tooltip formatter数据格式化
    格式化时间,推荐使用 scale: {mask: ‘YYYY-MM-DD HH:mm’}
    image.png

    1. import React from 'react';
    2. import {
    3. Chart,
    4. Geom,
    5. Axis,
    6. Tooltip,
    7. Legend,
    8. Annotation,
    9. Guide
    10. } from 'bizcharts';
    11. const { Line } = Guide;
    12. class LineChart extends React.Component {
    13. render() {
    14. const data = [
    15. {
    16. "month": "2020-07-13",
    17. "city": "gmv",
    18. "revenue": -0.2746803819927546
    19. },
    20. {
    21. "month": "2020-07-13",
    22. "city": "ipvmv",
    23. "revenue": -0.20788567741539923
    24. },
    25. {
    26. "month": "2020-07-14",
    27. "city": "gmv",
    28. "revenue": 1.1112345769215202
    29. },
    30. {
    31. "month": "2020-07-14",
    32. "city": "ipvmv",
    33. "revenue": 0.16731818696980633
    34. },
    35. {
    36. "month": "2020-07-15",
    37. "city": "gmv",
    38. "revenue": -0.21605967007286453
    39. },
    40. {
    41. "month": "2020-07-15",
    42. "city": "ipvmv",
    43. "revenue": 0.030564033267740633
    44. },
    45. {
    46. "month": "2020-07-16",
    47. "city": "gmv",
    48. "revenue": -0.023336570083636064
    49. },
    50. {
    51. "month": "2020-07-16",
    52. "city": "ipvmv",
    53. "revenue": 0.0230
    54. },
    55. {
    56. "month": "2020-07-17",
    57. "city": "gmv",
    58. "revenue": 0.0321
    59. },
    60. {
    61. "month": "2020-07-17",
    62. "city": "ipvmv",
    63. "revenue": -0.3583
    64. },
    65. {
    66. "month": "2020-07-18",
    67. "city": "gmv",
    68. "revenue": -0.3579
    69. },
    70. {
    71. "month": "2020-07-18",
    72. "city": "ipvmv",
    73. "revenue": 0.0416
    74. },
    75. {
    76. "month": "2020-07-19",
    77. "city": "gmv",
    78. "revenue": 0.2969
    79. },
    80. {
    81. "month": "2020-07-19",
    82. "city": "ipvmv",
    83. "revenue": 0.0486
    84. }
    85. ];
    86. const scale = {
    87. "revenue": {
    88. "range": [
    89. 0,
    90. 1
    91. ],
    92. "ticks": [
    93. 0,
    94. 1,
    95. 2,
    96. 3,
    97. 4,
    98. 5,
    99. 6
    100. ]
    101. },
    102. "month": {
    103. "range":[0.05, 0.95]
    104. }
    105. };
    106. const guide = {
    107. "type": "line",
    108. "start": {
    109. "month": "2020-07-14",
    110. "revenue": "0"
    111. },
    112. "end": {
    113. "month": "2020-07-14",
    114. "revenue": "1"
    115. },
    116. "lineStyle": {
    117. "stroke": "#999",
    118. "lineDash": [
    119. 0,
    120. 1,
    121. 1
    122. ],
    123. "lineWidth": 1
    124. },
    125. "text": {
    126. "position": "start",
    127. "autoRotate": true,
    128. "style": {
    129. "fill": "red"
    130. },
    131. "offsetX": 20,
    132. "offsetY": -20,
    133. "content": "待测试"
    134. }
    135. };
    136. return (
    137. <Chart height={400} data={data} scale={scale} autoFit>
    138. <Legend />
    139. <Axis name="month" />
    140. <Axis
    141. name="revenue"
    142. label={{
    143. formatter: val => `${val}亿`,
    144. }}
    145. />
    146. <Tooltip
    147. showCrosshairs
    148. shared
    149. />
    150. <Geom type="line" tooltip={['revenue*city', (value, name) => {
    151. return {
    152. value: `${value.toFixed(3)} 亿`,
    153. name
    154. }
    155. }]} position="month*revenue" size={2} color={'city'} />
    156. <Geom
    157. type="point"
    158. tooltip={false}
    159. position="month*revenue"
    160. size={4}
    161. shape={'circle'}
    162. color={'city'}
    163. style={{
    164. stroke: '#fff',
    165. lineWidth: 1,
    166. }}
    167. />
    168. <Guide>
    169. <Line
    170. start={{
    171. "month": "2020-07-14",
    172. "revenue": "0"
    173. }}
    174. end={{
    175. "month": "2020-07-14",
    176. "revenue": "1"
    177. }}
    178. lineStyle={{
    179. "stroke": "#999",
    180. "lineDash": [
    181. 0,
    182. 1,
    183. 1
    184. ],
    185. "lineWidth": 1
    186. }}
    187. text={{
    188. "position": "start",
    189. "autoRotate": false,
    190. "style": {
    191. "fill": "red"
    192. },
    193. "offsetX": 20,
    194. "offsetY": -20,
    195. "content": "待测试"
    196. }}
    197. />
    198. </Guide>
    199. <Annotation.Text
    200. position={['50%', '50%']}
    201. alignX="middle"
    202. alignY="middle"
    203. html={`<div style="color:#8c8c8c;font-size:1.16em;text-align: center;width: 10em;">项目总数<br><span style="color:red;font-size:2.5em;">${200}</span></div>`}
    204. />
    205. </Chart>
    206. );
    207. }
    208. }
    209. export default LineChart