index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. scale = {},
  14. borderWidth = 2,
  15. line,
  16. xAxis,
  17. yAxis,
  18. animate = true,
  19. } = this.props;
  20. const borderColor = this.props.borderColor || color;
  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 name="x" label={false} line={false} tickLine={false} grid={false} {...xAxis} />
  54. <Axis name="y" label={false} line={false} tickLine={false} grid={false} {...yAxis} />
  55. <Tooltip showTitle={false} crosshairs={false} />
  56. <Geom
  57. type="area"
  58. position="x*y"
  59. color={color}
  60. tooltip={tooltip}
  61. shape="smooth"
  62. style={{
  63. fillOpacity: 1,
  64. }}
  65. />
  66. {line ? (
  67. <Geom
  68. type="line"
  69. position="x*y"
  70. shape="smooth"
  71. color={borderColor}
  72. size={borderWidth}
  73. tooltip={false}
  74. />
  75. ) : (
  76. <span style={{ display: 'none' }} />
  77. )}
  78. </Chart>
  79. )}
  80. </div>
  81. </div>
  82. );
  83. }
  84. }