折线图

image.png

  1. import React,{useState} from 'react'
  2. import { Chart, Geom, Axis, Tooltip, Legend, Coord,Guide,Line } from 'bizcharts';
  3. const XianB = (props)=>{
  4. const [data, setData] = useState([
  5. {
  6. year: "1991",
  7. value: 3
  8. },
  9. {
  10. year: "1992",
  11. value: 4
  12. },
  13. {
  14. year: "1993",
  15. value: 3.5
  16. },
  17. {
  18. year: "1994",
  19. value: 5
  20. },
  21. {
  22. year: "1995",
  23. value: 4.9
  24. },
  25. {
  26. year: "1996",
  27. value: 6
  28. },
  29. {
  30. year: "1997",
  31. value: 7
  32. },
  33. {
  34. year: "1998",
  35. value: 9
  36. },
  37. {
  38. year: "1999",
  39. value: 13
  40. }
  41. ])
  42. const [cols, setCols] = useState( {
  43. value: {
  44. min: 0,
  45. range:[0,0.93],
  46. alias:'次'
  47. },
  48. year: {
  49. range: [0, 0.9],
  50. alias:'时间'
  51. }
  52. })
  53. return <div>
  54. <h3> 折线图 </h3>
  55. <Chart height={400} data={data} scale={cols} forceFit>
  56. <Axis name="year" title={{
  57. position:'end',
  58. offset:15,
  59. textStyle: {
  60. fontSize: '12',
  61. textAlign: 'center',
  62. fill: '#999',
  63. fontWeight: 'bold',
  64. rotate: 0,
  65. autoRotate:true
  66. }
  67. }} />
  68. <Axis name="value" title={{
  69. position:'end',
  70. offset:5.5,
  71. textStyle: {
  72. fontSize: '12',
  73. textAlign: 'right',
  74. fill: '#999',
  75. fontWeight: 'bold',
  76. rotate: 0
  77. }
  78. }}/>
  79. <Tooltip
  80. crosshairs={{
  81. type: "y"
  82. }}
  83. />
  84. <Geom type="line" position="year*value" size={2}
  85. tooltip={['year*value',(year,value)=>{
  86. return {
  87. name:'数值', // 要显示的名字
  88. value:value,
  89. title:year
  90. }
  91. }]} />
  92. <Geom
  93. type="point"
  94. position="year*value"
  95. size={4}
  96. shape={"circle"}
  97. style={{
  98. stroke: "#fff",
  99. lineWidth: 1
  100. }}
  101. tooltip={['year*value',(year,value)=>{
  102. return {
  103. name:'数值', // 要显示的名字
  104. value:value,
  105. title:year
  106. }
  107. }]}
  108. />
  109. </Chart>
  110. </div>
  111. }
  112. const XinaC = (props) =>{
  113. const [data,setData] = useState([
  114. {
  115. month: "Jan",
  116. city: "Tokyo",
  117. temperature: 7
  118. },
  119. {
  120. month: "Jan",
  121. city: "London",
  122. temperature: 3.9
  123. },
  124. {
  125. month: "Feb",
  126. city: "Tokyo",
  127. temperature: 6.9
  128. },
  129. {
  130. month: "Feb",
  131. city: "London",
  132. temperature: 4.2
  133. },
  134. {
  135. month: "Mar",
  136. city: "Tokyo",
  137. temperature: 9.5
  138. },
  139. {
  140. month: "Mar",
  141. city: "London",
  142. temperature: 5.7
  143. },
  144. {
  145. month: "Apr",
  146. city: "Tokyo",
  147. temperature: 14.5
  148. },
  149. {
  150. month: "Apr",
  151. city: "London",
  152. temperature: 8.5
  153. },
  154. {
  155. month: "May",
  156. city: "Tokyo",
  157. temperature: 18.4
  158. },
  159. {
  160. month: "May",
  161. city: "London",
  162. temperature: 11.9
  163. },
  164. {
  165. month: "Jun",
  166. city: "Tokyo",
  167. temperature: 21.5
  168. },
  169. {
  170. month: "Jun",
  171. city: "London",
  172. temperature: 15.2
  173. },
  174. {
  175. month: "Jul",
  176. city: "Tokyo",
  177. temperature: 25.2
  178. },
  179. {
  180. month: "Jul",
  181. city: "London",
  182. temperature: 17
  183. },
  184. {
  185. month: "Aug",
  186. city: "Tokyo",
  187. temperature: 26.5
  188. },
  189. {
  190. month: "Aug",
  191. city: "London",
  192. temperature: 16.6
  193. },
  194. {
  195. month: "Sep",
  196. city: "Tokyo",
  197. temperature: 23.3
  198. },
  199. {
  200. month: "Sep",
  201. city: "London",
  202. temperature: 14.2
  203. },
  204. {
  205. month: "Oct",
  206. city: "Tokyo",
  207. temperature: 18.3
  208. },
  209. {
  210. month: "Oct",
  211. city: "London",
  212. temperature: 10.3
  213. },
  214. {
  215. month: "Nov",
  216. city: "Tokyo",
  217. temperature: 13.9
  218. },
  219. {
  220. month: "Nov",
  221. city: "London",
  222. temperature: 6.6
  223. },
  224. {
  225. month: "Dec",
  226. city: "Tokyo",
  227. temperature: 9.6
  228. },
  229. {
  230. month: "Dec",
  231. city: "London",
  232. temperature: 4.8
  233. }
  234. ])
  235. const [cols,setCols] = useState({
  236. month: {
  237. range: [0, 1]
  238. }
  239. })
  240. return <div>
  241. <h3> 多条 曲线折线图 </h3>
  242. <Chart height={400} data={data} scale={cols} forceFit>
  243. <Legend />
  244. <Axis name="month" />
  245. <Axis
  246. name="temperature"
  247. label={{
  248. formatter: val => `${valC`
  249. }}
  250. />
  251. <Tooltip
  252. crosshairs={{
  253. type: "y"
  254. }}
  255. />
  256. <Geom
  257. type="line"
  258. position="month*temperature"
  259. size={2}
  260. color={"city"}
  261. shape={"smooth"}
  262. />
  263. <Geom
  264. type="point"
  265. position="month*temperature"
  266. size={4}
  267. shape={"circle"}
  268. color={"city"}
  269. style={{
  270. stroke: "#fff",
  271. lineWidth: 1
  272. }}
  273. />
  274. </Chart>
  275. </div>
  276. }

柱状图

image.png

const XianA = (props)=>{
    // 数据源
    const [data,setData] = useState([
        { genre: 'Sports', sold: 275, income: 2300 },
        { genre: 'Strategy', sold: 115, income: 667 },
        { genre: 'Action', sold: 120, income: 982 },
        { genre: 'Shooter', sold: 350, income: 5271 },
        { genre: 'Other', sold: 150, income: 3710 }
    ])

    // 定义度量
    const [cols,setCols] = useState({
            sold: { alias: '销售量' },
            genre: { alias: '游戏种类' }
        })

    return <div>
        <h3>柱状图</h3>
        <Chart width={600} height={400} data={data} scale={cols}>
            <Axis name="genre" title/>
            <Axis name="sold" title/>
            <Legend position="top" dy={-20} />
            <Tooltip />
            <Geom type="interval" position="genre*sold" color="genre" />
        </Chart>
    </div>
}