Top Related Projects
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Simple HTML5 Charts using the <canvas> tag
Open-source JavaScript charting library behind Plotly and Dash
Highcharts JS, the JavaScript charting framework
📊 Interactive JavaScript Charts built on SVG
Quick Overview
C3.js is a D3-based reusable chart library that allows developers to create highly customizable and interactive charts for web applications. It provides a simple and intuitive API for generating a variety of chart types, including line charts, bar charts, scatter plots, and more.
Pros
- Highly Customizable: C3.js offers a wide range of customization options, allowing developers to tailor the appearance and behavior of the charts to their specific needs.
- Reusable Components: The library's modular design makes it easy to reuse chart components across different parts of an application.
- Smooth Transitions: C3.js provides smooth transitions between chart updates, creating a visually appealing user experience.
- D3.js Integration: By building on top of D3.js, C3.js inherits the powerful data visualization capabilities of its parent library.
Cons
- Limited Chart Types: While C3.js supports a variety of chart types, it may not have the full range of options available in other charting libraries.
- Steep Learning Curve: Developers new to D3.js may find the learning curve for C3.js to be relatively steep, as it requires understanding both C3.js and D3.js.
- Performance Concerns: For large datasets or complex charts, C3.js may not perform as well as more specialized charting libraries.
- Dependency on D3.js: C3.js is heavily dependent on D3.js, which means that the entire D3.js library must be included in the project, even if only a few of its features are used.
Code Examples
Here are a few examples of how to use C3.js to create different types of charts:
Line Chart
var chart = c3.generate({
bindto: '#chart',
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 50, 20, 10, 40, 15, 25]
]
}
});
This code creates a simple line chart with two data series.
Bar Chart
var chart = c3.generate({
bindto: '#chart',
data: {
type: 'bar',
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 50, 20, 10, 40, 15, 25]
]
}
});
This code creates a bar chart with two data series.
Scatter Plot
var chart = c3.generate({
bindto: '#chart',
data: {
type: 'scatter',
columns: [
['data1', 3.2, 3.1, 3.5, 3.0, 3.6, 3.2],
['data2', 3.1, 3.0, 3.4, 3.5, 3.2, 3.1]
]
}
});
This code creates a scatter plot with two data series.
Getting Started
To get started with C3.js, follow these steps:
- Include the C3.js and D3.js libraries in your HTML file:
<link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.20/c3.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/6.7.0/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.20/c3.min.js"></script>
- Create a container element for the chart:
<div id="chart"></div>
- Initialize the chart in your JavaScript code:
var chart = c3.generate({
bindto: '#chart',
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
Competitor Comparisons
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 library with a wide range of chart types and data manipulation tools
- Large community and ecosystem with numerous extensions and resources
Cons of D3
- Steeper learning curve due to its low-level nature
- Requires more code to create basic charts compared to C3
- Less suitable for quick prototyping or simple visualizations
Code Comparison
D3 (creating a basic bar chart):
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 * 70)
.attr("y", d => 300 - d * 10)
.attr("width", 65).attr("height", d => d * 10);
C3 (creating a basic bar chart):
c3.generate({
data: {
columns: [
['data', 30, 200, 100, 400, 150, 250]
],
type: 'bar'
}
});
This comparison highlights the simplicity of C3 for basic charts, while D3 offers more control but requires more code. D3 is better suited for complex, custom visualizations, while C3 excels in quickly creating standard charts with less code.
Simple HTML5 Charts using the <canvas> tag
Pros of Chart.js
- Lighter weight and faster rendering compared to C3
- More customization options and flexibility in chart designs
- Larger community and more frequent updates
Cons of Chart.js
- Steeper learning curve for beginners
- Less built-in chart types compared to C3
Code Comparison
C3 example:
var chart = c3.generate({
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 50, 20, 10, 40, 15, 25]
],
type: 'bar'
}
});
Chart.js example:
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3]
}]
}
});
Both libraries offer powerful charting capabilities, but Chart.js provides more modern features and customization options. C3 is built on top of D3.js, which can be beneficial for those familiar with D3, while Chart.js is a standalone library. Chart.js has a larger community and more frequent updates, potentially leading to better long-term support and feature development.
Open-source JavaScript charting library behind Plotly and Dash
Pros of Plotly.js
- More extensive chart types and customization options
- Better support for scientific and statistical visualizations
- Larger and more active community, with frequent updates
Cons of Plotly.js
- Steeper learning curve due to more complex API
- Larger file size, which may impact page load times
- Some advanced features require a commercial license
Code Comparison
C3.js:
var chart = c3.generate({
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 50, 20, 10, 40, 15, 25]
],
type: 'bar'
}
});
Plotly.js:
Plotly.newPlot('myDiv', [{
x: [1, 2, 3, 4, 5, 6],
y: [30, 200, 100, 400, 150, 250],
type: 'bar'
}, {
x: [1, 2, 3, 4, 5, 6],
y: [50, 20, 10, 40, 15, 25],
type: 'bar'
}]);
Both libraries offer powerful charting capabilities, but Plotly.js provides more advanced features and customization options at the cost of increased complexity. C3.js, built on top of D3.js, offers a simpler API and easier integration for basic charts, making it more suitable for quick implementations and simpler visualizations.
Highcharts JS, the JavaScript charting framework
Pros of Highcharts
- More extensive chart types and customization options
- Better documentation and community support
- Smoother animations and interactivity
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
C3.js:
var chart = c3.generate({
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 50, 20, 10, 40, 15, 25]
],
type: 'line'
}
});
Highcharts:
Highcharts.chart('container', {
series: [{
name: 'data1',
data: [30, 200, 100, 400, 150, 250]
}, {
name: 'data2',
data: [50, 20, 10, 40, 15, 25]
}]
});
Both C3 and Highcharts are powerful charting libraries, but they cater to different needs. C3 is built on top of D3.js and offers a simpler API, making it easier for beginners to create basic charts quickly. It's open-source and free to use, which is advantageous for small projects or those with budget constraints.
Highcharts, on the other hand, provides a more comprehensive set of features and chart types, making it suitable for complex data visualization needs. Its extensive documentation and community support can be beneficial for larger projects or teams. However, the commercial licensing requirement may be a drawback for some users.
📊 Interactive JavaScript Charts built on SVG
Pros of ApexCharts.js
- More extensive and modern feature set, including animations and interactivity
- Better documentation and examples
- Responsive design and mobile-friendly out of the box
Cons of ApexCharts.js
- Larger file size, which may impact page load times
- Steeper learning curve due to more complex API
Code Comparison
C3.js:
var chart = c3.generate({
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 50, 20, 10, 40, 15, 25]
],
type: 'line'
}
});
ApexCharts.js:
var options = {
series: [{
name: 'data1',
data: [30, 200, 100, 400, 150, 250]
}, {
name: 'data2',
data: [50, 20, 10, 40, 15, 25]
}],
chart: {
type: 'line'
}
};
var chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();
Both libraries offer similar basic functionality for creating charts, but ApexCharts.js provides more customization options and a more modern API structure. C3.js has a simpler syntax, which may be preferable for basic use cases or quick implementations.
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
c3
c3 is a D3-based reusable chart library that enables deeper integration of charts into web applications.
Follow the link for more information: http://c3js.org
Documentation
Additional samples can be found in this repository:
You can run these samples as:
$ npm run serve-static
Google Group
For general C3.js-related discussion, please visit our Google Group at https://groups.google.com/forum/#!forum/c3js.
Gitter
Using the issue queue
The issue queue is to be used for reporting defects and problems with C3.js, in addition to feature requests and ideas. It is not a catch-all support forum. For general support enquiries, please use the Google Group at https://groups.google.com/forum/#!forum/c3js. All questions involving the interplay between C3.js and any other library (such as AngularJS) should be posted there first!
Before reporting an issue, please do the following:
-
Search for existing issues to ensure you're not posting a duplicate.
-
Search the Google Group to ensure it hasn't been addressed there already.
-
Create a JSFiddle or Plunkr highlighting the issue. Please don't include any unnecessary dependencies so we can isolate that the issue is in fact with C3. Please be advised that custom CSS can modify C3.js output!
-
When posting the issue, please use a descriptive title and include the version of C3 (or, if cloning from Git, the commit hash â C3 is under active development and the master branch contains the latest dev commits!), along with any platform/browser/OS information that may be relevant.
Pull requests
Pull requests are welcome, though please post an issue first to see whether such a change is desirable. If you choose to submit a pull request, please do not bump the version number unless asked to, and please include test cases for any new features. Squash all your commits as well, please.
Playground
Please fork this fiddle:
Dependency
- D3.js
^5.0.0
License
MIT
Top Related Projects
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Simple HTML5 Charts using the <canvas> tag
Open-source JavaScript charting library behind Plotly and Dash
Highcharts JS, the JavaScript charting framework
📊 Interactive JavaScript Charts built on SVG
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