index.js 1.12 KB
Newer Older
niko's avatar
niko committed
1 2 3
import React from 'react';
import { Chart, Tooltip, Geom } from 'bizcharts';
import autoHeight from '../autoHeight';
4 5
import styles from '../index.less';

niko's avatar
niko committed
6
@autoHeight()
afc163's avatar
afc163 committed
7
class MiniBar extends React.Component {
niko's avatar
niko committed
8 9
  render() {
    const { height, forceFit = true, color = '#1890FF', data = [] } = this.props;
10

niko's avatar
niko committed
11
    const scale = {
12 13 14 15 16 17
      x: {
        type: 'cat',
      },
      y: {
        min: 0,
      },
niko's avatar
niko committed
18
    };
19

niko's avatar
niko committed
20
    const padding = [36, 5, 30, 5];
21

niko's avatar
niko committed
22 23 24 25 26 27 28
    const tooltip = [
      'x*y',
      (x, y) => ({
        name: x,
        value: y,
      }),
    ];
29

niko's avatar
niko committed
30 31
    // for tooltip not to be hide
    const chartHeight = height + 54;
32 33 34

    return (
      <div className={styles.miniChart} style={{ height }}>
35
        <div className={styles.chartContent}>
niko's avatar
niko committed
36 37 38 39 40 41 42 43 44 45
          <Chart
            scale={scale}
            height={chartHeight}
            forceFit={forceFit}
            data={data}
            padding={padding}
          >
            <Tooltip showTitle={false} crosshairs={false} />
            <Geom type="interval" position="x*y" color={color} tooltip={tooltip} />
          </Chart>
46 47 48 49 50
        </div>
      </div>
    );
  }
}
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
51
export default MiniBar;