@gravity-ui/chartkit · npm package License CI storybook
Plugin-based React component that provides a unified rendering interface for multiple charting libraries. You register one or more plugins and render charts via <ChartKit type="..." data={...} /> — ChartKit dispatches to the correct renderer automatically.
Each plugin renderer is lazy-loaded, so the underlying library code is only downloaded when ChartKit is actually rendered in the UI. ChartKit also handles mobile-friendly tooltip display out of the box. You can use the built-in plugins or implement your own.
When to use:
- You need modern declarative charts (
gravity-charts) or time-series / monitoring charts (yagr) - You need multiple chart types under a single consistent API
- You're building in the Gravity UI ecosystem
When not to use:
- You only need one specific chart library — prefer using @gravity-ui/charts directly
- React 16, 17, or 18
[@gravity-ui/uikit](https://github.com/gravity-ui/uikit)— required peer dependency (provides theming and UI primitives)
npm install @gravity-ui/chartkit @gravity-ui/uikitImport the styles from @gravity-ui/uikit in your entry point:
import '@gravity-ui/uikit/styles/fonts.css';
import '@gravity-ui/uikit/styles/styles.css';For full setup details see the uikit styles guide.
ChartKit uses a global plugin registry. Call settings.set once at your app entry point to register the plugins you need. When <ChartKit type="..." /> renders, it looks up the matching plugin — if none is found, an error is thrown. Each plugin's renderer is a React.lazy component, so its code is fetched only when ChartKit first appears in the UI.
You can register multiple plugins at once:
settings.set({plugins: [GravityChartsPlugin, YagrPlugin]});Or call settings.set multiple times — it merges the plugin list rather than replacing it.
Basic example:
import {ThemeProvider} from '@gravity-ui/uikit';
import ChartKit, {settings} from '@gravity-ui/chartkit';
import {GravityChartsPlugin} from '@gravity-ui/chartkit/gravity-charts';
import '@gravity-ui/uikit/styles/fonts.css';
import '@gravity-ui/uikit/styles/styles.css';
settings.set({plugins: [GravityChartsPlugin]});
const data = {
series: {
data: [
{
type: 'line',
name: 'Series',
data: [
{x: 0, y: 10},
{x: 1, y: 25},
{x: 2, y: 18},
{x: 3, y: 30},
],
},
],
},
};
export default function App() {
return (
<ThemeProvider theme="light">
<div style={{height: 300}}>
<ChartKit type="gravity-charts" data={data} />
</div>
</ThemeProvider>
);
}ChartKit adapts to its parent's size — make sure the container has an explicit height.
Clone the repository and install dependencies:
git clone https://github.com/gravity-ui/ChartKit.git
cd ChartKit
npm cinpm run startStorybook will be available at http://localhost:7007.
To work on a dependency (e.g. @gravity-ui/charts) and see your changes live in Storybook without publishing to npm:
1. Link the local package
# In your local clone of @gravity-ui/charts:
git clone https://github.com/gravity-ui/charts.git
cd charts
npm ci
# make your changes
npm run build
npm link
# In ChartKit:
npm link @gravity-ui/charts2. Configure local package watching
Create a .env.local file in the ChartKit root (it is gitignored):
LOCAL_PKG=@gravity-ui/chartsThis tells Vite to watch that package in node_modules and skip pre-bundling it. After rebuilding @gravity-ui/charts, Storybook will hot-reload automatically.
For multiple packages, use a comma-separated list:
LOCAL_PKG=@gravity-ui/charts,@gravity-ui/uikit3. Start Storybook
npm run start4. Restore the original package
When you're done:
- Comment out
LOCAL_PKGin.env.local - Run
npm installin ChartKit — it replaces the symlink with the registry version
# In ChartKit:
npm cinpm testVisual regression tests run in Docker to ensure consistent screenshots across environments:
npm run test:dockerTo update the reference screenshots after intentional UI changes:
npm run test:docker:updatePlease refer to the contributing guide before submitting a pull request.