Get started
Carbon charts help you tell accurate and convincing stories around data with beautiful and accessible visualizations.
Note: Please direct all questions regarding support, bug fixes, and feature requests to the Carbon Charts core team.
Resources
Download WIP charting design specifications (IBM internal link)
Carbon Charts Vanilla library
The library provides a collection of reusable charting components to build websites and user interfaces. Adopting the library enables developers to use consistent markup, styles, and behavior in prototype and production work.
Install
If using yarn:
$ yarn add @carbon/charts d3
If you prefer npm:
$ npm install --save @carbon/charts d3
Getting started
If consuming through a bundler (e.g. webpack):
index.html...<div id="my-bar-chart"></div>...
index.jsimport '@carbon/charts/styles.css';import { BarChart, defaultColors } from '@carbon/charts';// grab chart holder DOM elementconst chartHolder = document.getElementById('my-bar-chart');// initialize the chartnew BarChart(chartHolder, {data: stackedBarData,options: stackedBarOptions,});
If consuming in a browser environment (e.g. through CDNs):
index.html<!DOCTYPE html><html><head><link rel="stylesheet" href="https://unpkg.com/@carbon/charts/style.css" /></head><body><div id="my-bar-chart"></div><script src="https://unpkg.com/@carbon/charts/bundle.js"></script><script>// grab chart holder DOM elementconst chartHolder = document.getElementById('my-bar-chart');const stackedBarData = {// ...see next section};const stackedBarOptions = {// ...see next section};// initialize the chartnew Charts.BarChart(chartHolder, {data: stackedBarData,options: stackedBarOptions,});</script></body></html>
Data and options
Data and options follow the same model in all charts, with minor exceptions and differences in specific components.
For instance, in the case of pie and donut charts, you would only provide one data set. In the case of donut charts, you can pass in an additional field called center
in your options configuring the donut center.
There are also additional options available depending on the chart type being used, for more examples please see here.
Below are sample data and options that can be used in a stacked bar chart:
import { BarChart, defaultColors } from '@carbon/charts';// Use the below if you're loading bundles through a CDN// const { BarChart, defaultColors } = Charts;const stackedBarData = {labels: ['Quantity', 'Leads', 'Sold', 'Restocking', 'Misc'],datasets: [{label: 'Dataset 1',backgroundColors: [defaultColors[0]],data: [65000, 29123, 35213, 51213, 16932],},{label: 'Dataset 2',backgroundColors: [defaultColors[1]],data: [32432, 21312, 56456, 21312, 34234],},{label: 'Dataset 3',backgroundColors: [defaultColors[2]],data: [12312, 23232, 34232, 12312, 34234],},],};const stackedBarOptions = {scales: {x: {title: '2018 Annual Sales',},y: {title: 'Figures',formatter: axisValue => {return `${axisValue / 1000}k`;},stacked: true,},},legendClickable: true,containerResizable: true,};
Development
Please refer to the Contribution Guidelines before starting any work.
Using the server
We recommend the use of Webpack Dev Server for developing components.
Start the server
cd packages/coreyarn run demo:server
Open browser to http://localhost:9001/
.
List of available components
View available components here.
Troubleshooting
If you experience any issues while getting set up with Carbon Charts, please head over to the GitHub repo for more guidelines and support. Please create an issue if your issue does not already exist.