index.js 1.11 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';

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

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

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

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

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

    return (
      <div className={styles.miniChart} style={{ height }}>
36
        <div className={styles.chartContent}>
niko's avatar
niko committed
37 38 39 40 41 42 43 44 45 46
          <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>
47 48 49 50 51
        </div>
      </div>
    );
  }
}