A high-performance React charting library built on Canvas
npm install @canplot/reactA high-performance React charting library built on Canvas.
š View live examples and documentation
- š High Performance: Built on Canvas for smooth rendering of large datasets
- š Multiple Chart Types: Line, Bar, Scatter, Area, and Sparkline plots
- šØ Customizable: Flexible styling and configuration options
- š Interactive: Built-in tooltips, crosshairs, and selection tools
- ā±ļø Time Series: First-class support for time-based data
- š± Responsive: Adapts to container size
- šÆ Type Safe: Written in TypeScript with full type definitions
``bash`
npm install @canplot/reactor
yarn add @canplot/reactor
pnpm add @canplot/reactor
bun add @canplot/react
`tsx
import { CanPlot, LinePlot } from '@canplot/react';
function MyChart() {
const data = [
{ x: 1, y: 30 },
{ x: 2, y: 45 },
{ x: 3, y: 60 },
{ x: 4, y: 35 },
{ x: 5, y: 70 },
];
const scales = [
{
id: 'x',
type: 'linear' as const,
axis: { position: 'bottom' as const, size: 40 },
origin: 'x' as const,
min: 0,
max: 10,
},
{
id: 'y',
type: 'linear' as const,
axis: { position: 'left' as const, size: 40 },
origin: 'y' as const,
min: 0,
max: 100,
},
];
return (
configuration={{
padding: { bottom: 20, left: 20, right: 20, top: 20 },
scales,
}}
>
xScaleId="x"
yScaleId="y"
style={{
strokeStyle: '#4c6ef5',
lineWidth: 2,
}}
/>
);
}
`
`tsx`
xScaleId="x"
yScaleId="y"
style={{ strokeStyle: '#4c6ef5', lineWidth: 2 }}
/>
`tsx`
xScaleId="x"
yScaleId="y"
barWidth={0.6}
xPositionOffset={0}
style={{ fillStyle: '#ff6b6b' }}
/>
`tsx`
xScaleId="x"
yScaleId="y"
style={{
fillStyle: '#51cf66',
strokeStyle: '#37b24d',
lineWidth: 2,
}}
/>
`tsx`
xScaleId="x"
yScaleId="y"
style={{
fillStyle: 'rgba(76, 110, 245, 0.2)',
strokeStyle: '#4c6ef5',
lineWidth: 2,
}}
/>
`tsx`
data={[
{
seriesId: 'series1',
yScaleId: 'y',
points: data,
},
]}
renderTooltip={(state) => {
if (!state || state.points[0].y === null) return null;
return (
tooltip styles / }}>
X: {state.x.toFixed(1)}, Y: {state.points[0].y?.toFixed(1)}
);
}}
/>
`tsx`
`tsx`
console.log('Selected area:', selection);
}}
/>
`tsx
const startDate = new Date('2024-01-01T00:00:00Z');
const scales = [
{
id: 'x',
type: 'time' as const,
axis: { position: 'bottom' as const, size: 40 },
origin: 'x' as const,
min: startDate.getTime(),
max: startDate.getTime() + 30 24 60 60 1000,
timeZone: 'UTC',
},
// ... y scale
];
const data = Array.from({ length: 30 }, (_, i) => ({
x: startDate.getTime() + i 24 60 60 1000,
y: Math.random() * 100,
}));
`
- CanPlot: Main container component
- LinePlot: Renders line charts
- BarPlot: Renders bar charts
- ScatterPlot: Renders scatter plots
- AreaPlot: Renders area charts
- SparklinePlot: Renders compact sparkline charts
- ChartAreaInteractions: Container for interactive features
- TooltipsX: Adds tooltips based on X-axis position
- Crosshair: Adds crosshair cursor
- SelectBox: Adds box selection
- AxisOverlay: Custom axis rendering
Full TypeScript type definitions are included.
If you encounter this error:
1. Install React type definitions:
`bash`
npm install --save-dev @types/react @types/react-dom
2. Check your tsconfig.json:
`json`
{
"compilerOptions": {
"moduleResolution": "bundler", // or "node16", "nodenext"
"esModuleInterop": true,
"skipLibCheck": false
}
}
3. Clear cache and reinstall:
`bash``
rm -rf node_modules/.cache
npm install
MIT
Contributions are welcome! Please feel free to submit a Pull Request.
https://github.com/jedzej/canplot