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.
Refer to the contribution guidelines before you start building. If you want to develop your own components, we recommend the Webpack Dev Server.
Visit the component status page for a complete list of available components.
$ yarn add @carbon/charts d3
$ npm install --save @carbon/charts d3
index.html...<div id="my-bar-chart"></div>...
index.jsimport '@carbon/charts/style.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,});
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/index.umd.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>
cd packages/coreyarn run demo:server
Launch your browser and go to http://localhost:9001/
.
Data and options follow the same model in all charts, with minor exceptions and differences in specific components.
For example, you only need to provide one data set for pie and donut charts. In the case of donut charts, you can pass in an additional field called center
in your options when configuring the donut center.
Additional options available vary by chart type. For more examples see the data demo.
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,};
If you experience any issues while getting started with Carbon Charts, head over to the GitHub repo for more guidance and support. Please create a GitHub issue if you find a bug or need more help.