A collection of tiny chart components for React projects. Written with TypeScript and CSS modules.
You can see an interactive preview of all components in the public Storybook instance. Use the "Controls" and "JSX" tabs in Storybook to customize the charts and get the code to paste into your project.
npm:
npm install --save react-mini-chartsyarn:
yarn add react-mini-chartsimport { BarChart } from 'react-mini-charts'
<BarChart
items={[
{
barWidth: '10%',
barColor: '#adfc92',
labels: {
left: { text: 'Something good' },
right: { text: '10%' },
},
},
{
barWidth: '50%',
barColor: '#4a0d67',
labels: {
left: { text: 'Something mediocre' },
right: { text: '50%' },
},
},
{
barWidth: '40%',
barColor: '#db3069',
labels: {
left: { text: 'Something bad' },
right: { text: '40%' },
},
},
]}
/>import { PieChart } from 'react-mini-charts'
<PieChart
size={240}
items={[
{ percentage: 0.37, color: '#4a0d67' },
{ percentage: 0.21, color: '#db3069' },
{ percentage: 0.13, color: '#adfc92' },
]}
/>- General styles like
font-familyare inherited from the surrounding CSS context. - Specific chart styles can be overridden with
classNameprops. - By default, charts have transition styles that allow for smooth transitions between values. The timing and behavior can be overridden with custom CSS classes.
- Node 18.x with npm 9.x (other versions might work as well)
- Editor (e.g. VS Code) with TypeScript, ESLint and Prettier integration
- Install dependencies with
npm install - Start editing and preview your changes in Storybook with
npm run storybook
- Build the project to generate the output in
/distvianpm run build - Bump the version in
package.json - Re-run
npm installto update the version inpackage-lock.json - Update the
CHANGELOG.md - Publish to npm via
npm publish(you might need to log in first)
# Format all files according to Prettier config:
npm run format
# Run all tests:
npm testThis is a spare-time project by one person, but feedback is very welcome! Feel free to leave comments and suggestions as issues on GitHub!
- Make charts more responsive
- Add legend component
- Add more chart types (e.g. line chart, horizontal bar chart)
- Document requirements (e.g. minimum React version)
- Document difference between HTML-based and SVG-based charts
- Calculate the percentages based on absolute values (instead of percentages to be pre-calculated on the outside)

