ResponsiveChart

A wrapper component that provides responsive sizing for charts, automatically measuring container width and calculating height.

Basic Usage

Wrap your chart in ResponsiveChart and use the render function to receive the calculated dimensions:

tsx
import { ResponsiveChart, LineChart } from '@derpdaderp/chartkit';

<ResponsiveChart aspectRatio={16 / 9}>
  {({ width, height }) => (
    <LineChart
      data={data}
      series={series}
      theme="midnight"
      width={width}
      height={height}
    />
  )}
</ResponsiveChart>

Aspect Ratio

Use aspectRatio to maintain proportions. The chart will fill the container width and calculate height based on the ratio:

16:9
4:3

Fixed Height

Use height for a fixed pixel height while still getting responsive width:

tsx
<ResponsiveChart height={250}>
  {({ width, height }) => (
    <LineChart
      data={data}
      series={series}
      theme="midnight"
      width={width}
      height={height}
    />
  )}
</ResponsiveChart>

Min/Max Height

Constrain the calculated height with minHeight and maxHeight:

tsx
<ResponsiveChart 
  aspectRatio={16 / 9} 
  minHeight={200} 
  maxHeight={500}
>
  {({ width, height }) => (
    <LineChart
      data={data}
      series={series}
      theme="midnight"
      width={width}
      height={height}
    />
  )}
</ResponsiveChart>

Resize Debounce

Control how quickly the chart responds to window resizes with debounce:

tsx
// Fast response (less smooth)
<ResponsiveChart aspectRatio={16 / 9} debounce={50}>
  ...
</ResponsiveChart>

// Slower response (smoother)
<ResponsiveChart aspectRatio={16 / 9} debounce={200}>
  ...
</ResponsiveChart>

Full Container

When neither height nor aspectRatio is provided, the chart will fill 100% of its container:

tsx
<div style={{ height: '400px' }}>
  <ResponsiveChart>
    {({ width, height }) => (
      <LineChart
        data={data}
        series={series}
        theme="midnight"
        width={width}
        height={height}
      />
    )}
  </ResponsiveChart>
</div>

Props

PropTypeDefaultDescription
children*(dimensions: { width: number; height: number }) => ReactNode-Render function receiving dimensions
heightnumber-Fixed height in pixels
aspectRationumber-Aspect ratio (width/height)
minHeightnumber100Minimum height in pixels
maxHeightnumber-Maximum height in pixels
debouncenumber100Resize debounce in ms
classNamestring-Additional CSS class
styleCSSProperties-Additional styles