Billboard is a React component library that provides a declarative, component-based API for creating charts using Recharts. It offers both a props-based and component-based approach, making it flexible for different usage patterns while maintaining a consistent API.
npm install react-billboard
import { Billboard } from 'react-billboard';
const MyChart = () => (
<Billboard
type="line"
datasets={[{
name: "Revenue",
data: [
{ x: "Jan", y: 1000 },
{ x: "Feb", y: 1500 },
{ x: "Mar", y: 1200 }
],
color: "#4299E1",
style: {
strokeWidth: 2,
dot: true,
}
}]}
>
<Billboard.Chart className="h-[400px]" />
</Billboard>
);
const MyComponentChart = () => (
<Billboard type="line">
<Billboard.Chart className="h-[400px]">
<Billboard.Dataset
name="Revenue"
color="#4299E1"
style={{
strokeWidth: 2,
dot: true,
}}
>
<Billboard.Datapoint x="Jan" y={1000} />
<Billboard.Datapoint x="Feb" y={1500} />
<Billboard.Datapoint x="Mar" y={1200} />
</Billboard.Dataset>
</Billboard.Chart>
</Billboard>
);
const MyAreaChart = () => (
<Billboard type="area">
<Billboard.Chart className="h-[400px]">
<Billboard.Dataset
name="Revenue"
color="#4299E1"
style={{
fillOpacity: 0.3,
strokeWidth: 2,
}}
data={[
{ x: "Jan", y: 1000 },
{ x: "Feb", y: 1500 },
{ x: "Mar", y: 1200 }
]}
/>
<Billboard.Dataset
name="Profit"
color="#48BB78"
style={{
fillOpacity: 0.3,
strokeWidth: 2,
}}
data={[
{ x: "Jan", y: 300 },
{ x: "Feb", y: 450 },
{ x: "Mar", y: 350 }
]}
/>
</Billboard.Chart>
</Billboard>
);
Main container component for creating charts.
-
type
(required):'line' | 'area' | 'bar' | 'scatter' | 'pie'
-
datasets?
: Array of dataset objects (for props-based usage) -
className?
: CSS class name -
children?
: React nodes
Chart container component.
-
className?
: CSS class name (required for setting height) -
x?
: X-axis configuration{ title?: string; min?: number; max?: number; }
-
y?
: Y-axis configuration (same as x) -
children?
: Dataset components
Dataset container component.
-
name
: Dataset identifier -
color?
: Dataset color -
data?
: Array of data points -
style?
: Dataset styling options{ strokeWidth?: number; fillOpacity?: number; dot?: boolean; }
-
children?
: Datapoint components
Individual data point component. Must be a child of Dataset.
-
x
: X value (string | number) -
y
: Y value (number) -
color?
: Point color -
style?
: Point-specific styling
type ChartType = 'line' | 'area' | 'bar' | 'scatter' | 'pie';
interface DataPoint {
x: string | number;
y: number;
color?: string;
}
interface DatasetStyle {
strokeWidth?: number;
fillOpacity?: number;
dot?: boolean;
}
interface Dataset {
name: string;
data: DataPoint[];
color?: string;
style?: DatasetStyle;
}
The library uses Recharts under the hood and supports two types of styling:
- Container styling through className props
<Billboard.Chart className="h-[400px] w-full" />
- Chart-specific styling through the style prop
<Billboard.Dataset
style={{
strokeWidth: 2,
fillOpacity: 0.3,
dot: true
}}
/>
- Always provide a fixed height via className on Billboard.Chart
- Use consistent colors across related datasets
- For area charts, use fillOpacity for better visualization
- When using Datapoints, always place them inside a Dataset
- Use meaningful names for datasets to populate the legend
- The library currently supports basic chart types from Recharts
- Custom Recharts components must be added through the base Billboard props
- Some Recharts features require direct props configuration
- Animation options are inherited from Recharts defaults
Supports all modern browsers that support SVG and React.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
MIT