index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import React from 'react';
  2. import { Chart, Axis, Tooltip, Geom } from 'bizcharts';
  3. import autoHeight from '../autoHeight';
  4. import styles from '../index.less';
  5. @autoHeight()
  6. export default class MiniArea extends React.Component {
  7. render() {
  8. const {
  9. height,
  10. data = [],
  11. forceFit = true,
  12. color = 'rgba(24, 144, 255, 0.2)',
  13. borderColor = '#1089ff',
  14. scale = {},
  15. borderWidth = 2,
  16. line,
  17. xAxis,
  18. yAxis,
  19. animate = true,
  20. } = this.props;
  21. const padding = [36, 5, 30, 5];
  22. const scaleProps = {
  23. x: {
  24. type: 'cat',
  25. range: [0, 1],
  26. ...scale.x,
  27. },
  28. y: {
  29. min: 0,
  30. ...scale.y,
  31. },
  32. };
  33. const tooltip = [
  34. 'x*y',
  35. (x, y) => ({
  36. name: x,
  37. value: y,
  38. }),
  39. ];
  40. const chartHeight = height + 54;
  41. return (
  42. <div className={styles.miniChart} style={{ height }}>
  43. <div className={styles.chartContent}>
  44. {height > 0 && (
  45. <Chart
  46. animate={animate}
  47. scale={scaleProps}
  48. height={chartHeight}
  49. forceFit={forceFit}
  50. data={data}
  51. padding={padding}
  52. >
  53. <Axis
  54. key="axis-x"
  55. name="x"
  56. label={false}
  57. line={false}
  58. tickLine={false}
  59. grid={false}
  60. {...xAxis}
  61. />
  62. <Axis
  63. key="axis-y"
  64. name="y"
  65. label={false}
  66. line={false}
  67. tickLine={false}
  68. grid={false}
  69. {...yAxis}
  70. />
  71. <Tooltip showTitle={false} crosshairs={false} />
  72. <Geom
  73. type="area"
  74. position="x*y"
  75. color={color}
  76. tooltip={tooltip}
  77. shape="smooth"
  78. style={{
  79. fillOpacity: 1,
  80. }}
  81. />
  82. {line ? (
  83. <Geom
  84. type="line"
  85. position="x*y"
  86. shape="smooth"
  87. color={borderColor}
  88. size={borderWidth}
  89. tooltip={false}
  90. />
  91. ) : (
  92. <span style={{ display: 'none' }} />
  93. )}
  94. </Chart>
  95. )}
  96. </div>
  97. </div>
  98. );
  99. }
  100. }