"DashboardAnalysis/src/components/Charts/MiniBar/index.tsx" did not exist on "74b673e58ce549e0c9c3d9bc5433c044a29d220b"
index.tsx 1.43 KB
Newer Older
陈帅's avatar
陈帅 committed
1 2
import { Chart, Geom, Tooltip } from 'bizcharts';

陈帅's avatar
陈帅 committed
3 4 5 6 7 8 9
import React from 'react';
import autoHeight from '../autoHeight';
import styles from '../index.less';

export interface IMiniBarProps {
  color?: string;
  height?: number;
陈帅's avatar
陈帅 committed
10
  data: {
陈帅's avatar
陈帅 committed
11 12
    x: number | string;
    y: number;
陈帅's avatar
陈帅 committed
13
  }[];
陈帅's avatar
陈帅 committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
  forceFit?: boolean;
  style?: React.CSSProperties;
}

class MiniBar extends React.Component<IMiniBarProps> {
  render() {
    const { height = 0, forceFit = true, color = '#1890FF', data = [] } = this.props;

    const scale = {
      x: {
        type: 'cat',
      },
      y: {
        min: 0,
      },
    };

    const padding: [number, number, number, number] = [36, 5, 30, 5];

    const tooltip: [string, (...args: any[]) => { name?: string; value: string }] = [
      'x*y',
      (x: string, y: string) => ({
        name: x,
        value: y,
      }),
    ];

    // for tooltip not to be hide
    const chartHeight = height + 54;

    return (
      <div className={styles.miniChart} style={{ height }}>
        <div className={styles.chartContent}>
          <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>
        </div>
      </div>
    );
  }
}
export default autoHeight()(MiniBar);