carbon-charts
:bar_chart: :chart_with_upwards_trend:⠀Robust dataviz framework implemented using D3 & typescript
Top Related Projects
Simple HTML5 Charts using the <canvas> tag
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
JavaScript 3D Library.
Open-source JavaScript charting library behind Plotly and Dash
📊 Interactive JavaScript Charts built on SVG
Highcharts JS, the JavaScript charting framework
Quick Overview
Carbon Charts is an open-source charting library built on D3.js, designed to work seamlessly with the Carbon Design System. It provides a collection of reusable, responsive, and accessible chart components for data visualization in web applications, adhering to IBM's design principles.
Pros
- Consistent with Carbon Design System, ensuring a cohesive look and feel
- Highly customizable and flexible, supporting various chart types and options
- Built with accessibility in mind, following WCAG 2.1 guidelines
- Responsive design, adapting to different screen sizes and devices
Cons
- Learning curve for developers not familiar with D3.js or Carbon Design System
- Limited to chart types supported by the library
- May have performance issues with large datasets compared to more lightweight alternatives
- Documentation could be more comprehensive for advanced use cases
Code Examples
- Creating a simple bar chart:
import { BarChart } from "@carbon/charts";
const chartData = [
{ group: "Qty", value: 65000 },
{ group: "More", value: 29123 },
{ group: "Sold", value: 35213 },
{ group: "Restocking", value: 51213 },
];
const chart = new BarChart(document.getElementById("chart"), {
data: chartData,
options: {
title: "Simple bar chart",
axes: {
left: { mapsTo: "value" },
bottom: { mapsTo: "group", scaleType: "labels" },
},
height: "400px",
},
});
- Creating a line chart with multiple datasets:
import { LineChart } from "@carbon/charts";
const chartData = [
{ group: "Dataset 1", date: "2019-01-01", value: 10000 },
{ group: "Dataset 1", date: "2019-01-06", value: 65000 },
{ group: "Dataset 2", date: "2019-01-01", value: 30000 },
{ group: "Dataset 2", date: "2019-01-06", value: 20000 },
];
const chart = new LineChart(document.getElementById("chart"), {
data: chartData,
options: {
title: "Line chart with multiple datasets",
axes: {
bottom: { key: "date", type: "time" },
left: { mapsTo: "value" },
},
curve: "curveMonotoneX",
},
});
- Creating a pie chart with customized colors:
import { PieChart } from "@carbon/charts";
const chartData = [
{ group: "2V2N 9KYPM", value: 20 },
{ group: "L22I P66EP", value: 65 },
{ group: "JQAI 2M4L1", value: 75 },
{ group: "J9DZ F37AP", value: 15 },
];
const chart = new PieChart(document.getElementById("chart"), {
data: chartData,
options: {
title: "Pie chart with custom colors",
resizable: true,
color: {
scale: {
"2V2N 9KYPM": "#1192e8",
"L22I P66EP": "#005d5d",
"JQAI 2M4L1": "#9f1853",
"J9DZ F37AP": "#fa4d56",
},
},
},
});
Getting Started
- Install the package:
npm install @carbon/charts
- Import the necessary styles in your project:
import "@carbon/charts/styles.css";
- Create a chart instance:
import { BarChart } from "@carbon/charts";
const chart = new BarChart(document.getElementById("chart"), {
data: yourData,
options: yourOptions,
});
- Update the chart as needed:
chart
Competitor Comparisons
Simple HTML5 Charts using the <canvas> tag
Pros of Chart.js
- Wider community support and more extensive documentation
- Simpler API and easier learning curve for beginners
- Greater flexibility in customization options
Cons of Chart.js
- Less opinionated design, requiring more manual styling for consistency
- Fewer built-in chart types compared to Carbon Charts
- Limited support for complex data visualizations
Code Comparison
Carbon Charts:
import { BarChart } from "@carbon/charts";
const chart = new BarChart(document.getElementById("chart"), {
data: chartData,
options: chartOptions
});
Chart.js:
import Chart from 'chart.js/auto';
const chart = new Chart(document.getElementById('chart'), {
type: 'bar',
data: chartData,
options: chartOptions
});
Both libraries offer similar basic setup, but Carbon Charts provides more specific chart types out of the box, while Chart.js requires specifying the chart type in the configuration.
Carbon Charts is designed to integrate seamlessly with IBM's Carbon Design System, offering a consistent look and feel. Chart.js, on the other hand, provides more flexibility but requires additional effort to achieve a cohesive design across different chart types.
Chart.js has a larger ecosystem of plugins and extensions due to its popularity and longer presence in the market. However, Carbon Charts excels in enterprise-level applications, particularly those following IBM's design guidelines.
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Pros of d3
- Highly flexible and customizable, allowing for complex and unique visualizations
- Extensive documentation and large community support
- Powerful data manipulation and binding capabilities
Cons of d3
- Steeper learning curve, especially for beginners
- Requires more code to create basic charts
- Lower-level API, which can be time-consuming for simple visualizations
Code Comparison
d3:
const svg = d3.select("body").append("svg")
.attr("width", 400)
.attr("height", 300);
svg.selectAll("rect")
.data(data)
.enter()
.append("rect")
.attr("x", (d, i) => i * 40)
.attr("y", d => 300 - d * 10)
.attr("width", 35)
.attr("height", d => d * 10);
carbon-charts:
const chart = new BarChart(document.getElementById("chart"), {
data: data,
options: {
title: "Bar Chart",
axes: {
left: { mapsTo: "value" },
bottom: { mapsTo: "group" }
}
}
});
The code comparison demonstrates that carbon-charts provides a higher-level API for creating charts, requiring less code for basic visualizations compared to d3. However, d3 offers more granular control over chart elements and data binding.
JavaScript 3D Library.
Pros of three.js
- More versatile for 3D graphics and animations
- Larger community and ecosystem
- Extensive documentation and examples
Cons of three.js
- Steeper learning curve
- Potentially overkill for simple 2D charts
- Larger file size and potentially higher performance overhead
Code Comparison
three.js:
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
carbon-charts:
import { BarChart } from "@carbon/charts";
const chart = new BarChart(document.getElementById("chart"), {
data: chartData,
options: chartOptions
});
three.js is a powerful 3D graphics library that offers extensive capabilities for creating complex 3D scenes and animations. It has a large community and ecosystem, providing numerous resources and extensions. However, it comes with a steeper learning curve and may be excessive for simple 2D charting needs.
carbon-charts, on the other hand, is specifically designed for creating charts and graphs. It offers a more straightforward API for common chart types, making it easier to implement basic data visualizations. While it may lack the 3D capabilities of three.js, it's more focused and potentially more efficient for standard charting requirements.
Open-source JavaScript charting library behind Plotly and Dash
Pros of Plotly.js
- More extensive and diverse chart types, including 3D visualizations
- Highly interactive and customizable charts with built-in hover tooltips
- Large and active community, resulting in frequent updates and extensive documentation
Cons of Plotly.js
- Larger file size and potentially slower performance for complex visualizations
- Steeper learning curve due to its extensive feature set
- May require more configuration for consistent styling across different chart types
Code Comparison
Carbon Charts:
import { BarChart } from "@carbon/charts";
const chart = new BarChart(document.getElementById("chart"), {
data: chartData,
options: chartOptions
});
Plotly.js:
import Plotly from 'plotly.js-dist';
Plotly.newPlot('chart', chartData, chartLayout, chartConfig);
Both libraries offer straightforward ways to create charts, but Carbon Charts provides a more object-oriented approach, while Plotly.js uses a functional style. Carbon Charts may be easier to integrate with other Carbon Design System components, whereas Plotly.js offers more flexibility for complex visualizations.
📊 Interactive JavaScript Charts built on SVG
Pros of ApexCharts
- More extensive chart types and customization options
- Better performance with large datasets
- Active community and frequent updates
Cons of ApexCharts
- Steeper learning curve due to more complex API
- Larger file size, which may impact load times
- Less focus on accessibility features
Code Comparison
ApexCharts:
var options = {
chart: { type: 'bar' },
series: [{ data: [30, 40, 45, 50, 49, 60, 70, 91, 125] }],
xaxis: { categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999] }
};
var chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();
Carbon Charts:
const chart = new BarChart(document.getElementById('chart'));
chart.model.setData({
labels: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999],
datasets: [{ data: [30, 40, 45, 50, 49, 60, 70, 91, 125] }]
});
chart.render();
Both libraries offer similar functionality for creating charts, but ApexCharts provides more detailed configuration options out of the box, while Carbon Charts focuses on simplicity and adherence to the Carbon Design System.
Highcharts JS, the JavaScript charting framework
Pros of Highcharts
- More extensive documentation and examples
- Wider range of chart types and customization options
- Larger community and ecosystem
Cons of Highcharts
- Commercial license required for most use cases
- Steeper learning curve due to more complex API
- Larger file size, potentially impacting page load times
Code Comparison
Carbon Charts:
import { BarChart } from "@carbon/charts";
const chart = new BarChart(document.getElementById("chart"), {
data: chartData,
options: chartOptions
});
Highcharts:
import Highcharts from 'highcharts';
Highcharts.chart('container', {
chart: { type: 'bar' },
series: [{ data: chartData }],
// Additional options...
});
Summary
Highcharts offers a more comprehensive charting solution with extensive customization options and a larger ecosystem. However, it comes with a commercial license requirement and a steeper learning curve. Carbon Charts, while more limited in features, provides a simpler API and is open-source, making it suitable for projects with straightforward charting needs or those requiring IBM Carbon Design System compatibility.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Carbon Charts
A component library of 26 charts for vanilla JavaScript, Svelte, React, Vue.js and Angular.
Documentation
Includes StackBlitz examples of each chart type for supported frameworks.
Supported Versions
| Version | Supported |
|---|---|
| 1.x | :white_check_mark: |
| 0.x | â EOL |
Please review the release schedule for full details on what release phase versions are in and the level of support provided for each.
CHANGELOG
Release change logs can be found here.
Bugs and feature requests
Please read the issue guidelines and search for existing and closed issues. If your problem or idea has not been addressed, submit a bug report or feature enhancement request.
Contributing
See our contributing guidelines - instructions for opening issues, coding guidelines, and submitting pull requests.
Versioning
We use the semantic-release library to automatically version our releases within the guidelines of Semantic Versioning Semantic Versioning guidelines.
Core team
Previous core members
Contributors â¨
Code of Conduct
Read our code of conduct here
Top Related Projects
Simple HTML5 Charts using the <canvas> tag
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
JavaScript 3D Library.
Open-source JavaScript charting library behind Plotly and Dash
📊 Interactive JavaScript Charts built on SVG
Highcharts JS, the JavaScript charting framework
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot