dc.js
Multi-Dimensional charting built to work natively with crossfilter rendered with d3.js
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
📊 Re-usable, easy interface JavaScript chart library based on D3.js
Apache ECharts is a powerful, interactive charting and data visualization library for browser
Quick Overview
dc.js is a multi-dimensional charting library built on top of D3.js and Crossfilter. It provides a powerful and flexible way to create interactive, data-driven charts and dashboards in JavaScript. dc.js excels at exploring large, multi-dimensional datasets and allows for seamless linking between charts.
Pros
- Highly interactive and responsive charts
- Seamless integration with Crossfilter for efficient data manipulation
- Wide variety of chart types and customization options
- Strong community support and extensive documentation
Cons
- Steep learning curve for beginners
- Performance can degrade with very large datasets
- Limited mobile responsiveness out of the box
- Dependency on D3.js and Crossfilter may increase project complexity
Code Examples
- Creating a simple bar chart:
var chart = dc.barChart("#chart-container");
chart
.dimension(yearDimension)
.group(salesGroup)
.x(d3.scaleTime().domain([new Date(2020, 0, 1), new Date(2021, 11, 31)]))
.xUnits(d3.timeMonths);
- Adding a pie chart with custom colors:
var pieChart = dc.pieChart("#pie-chart-container");
pieChart
.dimension(categoryDimension)
.group(categoryGroup)
.colors(d3.scaleOrdinal().domain(["A", "B", "C"]).range(["#FF6384", "#36A2EB", "#FFCE56"]));
- Creating a line chart with a range chart:
var lineChart = dc.lineChart("#line-chart-container");
var rangeChart = dc.barChart("#range-chart-container");
lineChart
.dimension(dateDimension)
.group(valueGroup)
.x(d3.scaleTime().domain([minDate, maxDate]))
.rangeChart(rangeChart);
rangeChart
.dimension(dateDimension)
.group(valueGroup)
.x(d3.scaleTime().domain([minDate, maxDate]));
Getting Started
To get started with dc.js, follow these steps:
- Include the necessary libraries in your HTML file:
<link rel="stylesheet" href="https://unpkg.com/dc@4/dist/style/dc.css">
<script src="https://unpkg.com/d3@7"></script>
<script src="https://unpkg.com/crossfilter2@1.5/crossfilter.min.js"></script>
<script src="https://unpkg.com/dc@4/dist/dc.min.js"></script>
- Create a container for your chart in the HTML:
<div id="chart-container"></div>
- Initialize your data and create a chart:
// Assume 'data' is your dataset
var ndx = crossfilter(data);
var dimension = ndx.dimension(d => d.category);
var group = dimension.group().reduceSum(d => d.value);
var chart = dc.barChart("#chart-container");
chart
.dimension(dimension)
.group(group)
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.brushOn(false)
.yAxisLabel("Value");
dc.renderAll();
This will create a basic bar chart using dc.js. You can then customize and add more charts as needed.
Competitor Comparisons
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Pros of d3
- More flexible and powerful for creating custom visualizations
- Larger community and ecosystem with extensive documentation
- Can be used for a wider range of data visualization projects
Cons of d3
- Steeper learning curve and more complex to use
- Requires more code to create basic charts and graphs
- Less abstraction, which can lead to more verbose implementations
Code Comparison
d3 example:
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);
dc.js example:
const chart = dc.barChart("#chart");
chart
.width(400)
.height(300)
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.brushOn(false)
.yAxisLabel("Value")
.dimension(dimension)
.group(group);
chart.render();
dc.js is built on top of d3 and provides a higher-level abstraction for creating charts. It offers pre-built chart types and handles much of the complexity of d3, making it easier to create common visualizations quickly. However, it sacrifices some of the flexibility and customization options that d3 provides. d3 is more suitable for complex, custom visualizations, while dc.js is better for rapid development of standard chart types.
Simple HTML5 Charts using the <canvas> tag
Pros of Chart.js
- Simpler API and easier to get started with for basic charts
- Wider variety of chart types out of the box
- Smoother animations and transitions
Cons of Chart.js
- Less powerful for complex data visualizations and interactions
- Limited support for real-time data updates
- Fewer options for data filtering and cross-filtering
Code Comparison
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]
}]
}
});
dc.js example:
var chart = dc.barChart("#chart");
chart
.width(768)
.height(480)
.x(d3.scale.ordinal())
.xUnits(dc.units.ordinal)
.brushOn(false)
.xAxisLabel("Fruit")
.yAxisLabel("Quantity Sold")
.dimension(fruitDimension)
.group(fruitGroup);
Chart.js is more concise for simple charts, while dc.js offers more granular control and integration with Crossfilter for complex data manipulations.
Open-source JavaScript charting library behind Plotly and Dash
Pros of plotly.js
- More extensive chart types and customization options
- Better support for 3D visualizations
- Easier to create interactive and responsive charts
Cons of plotly.js
- Larger file size, which may impact page load times
- Steeper learning curve due to more complex API
- Less integrated with data manipulation libraries like Crossfilter
Code Comparison
plotly.js:
Plotly.newPlot('myDiv', [{
x: [1, 2, 3, 4],
y: [10, 15, 13, 17],
type: 'scatter'
}]);
dc.js:
var chart = dc.lineChart("#myDiv");
chart
.dimension(dateDimension)
.group(dateGroup)
.x(d3.scaleTime().domain([minDate, maxDate]));
Summary
plotly.js offers a wider range of chart types and customization options, making it suitable for complex visualizations. It excels in creating interactive and responsive charts, especially for 3D visualizations. However, it has a larger file size and a steeper learning curve.
dc.js, on the other hand, is more lightweight and integrates well with data manipulation libraries like Crossfilter. It's easier to learn but offers fewer chart types and customization options compared to plotly.js.
The choice between the two depends on the specific requirements of your project, such as the complexity of visualizations needed, performance considerations, and integration with other libraries in your stack.
📊 Re-usable, easy interface JavaScript chart library based on D3.js
Pros of billboard.js
- More active development with frequent updates and releases
- Broader range of chart types and customization options
- Better documentation and examples for easier implementation
Cons of billboard.js
- Steeper learning curve due to more complex API
- Larger file size, which may impact page load times
- Less focus on data-driven, interactive visualizations compared to dc.js
Code Comparison
dc.js:
var chart = dc.barChart("#chart");
chart
.dimension(dimension)
.group(group)
.x(d3.scale.ordinal())
.xUnits(dc.units.ordinal);
billboard.js:
var chart = bb.generate({
bindto: "#chart",
data: {
columns: [["data1", 30, 200, 100, 400, 150, 250]]
},
type: "bar"
});
Both libraries offer declarative approaches to creating charts, but billboard.js provides a more configuration-based setup, while dc.js focuses on chaining methods for customization. dc.js is built on top of D3.js and Crossfilter, making it powerful for interactive, data-driven visualizations. billboard.js, on the other hand, offers a wider variety of chart types out of the box and may be easier for beginners to get started with simple charts.
Apache ECharts is a powerful, interactive charting and data visualization library for browser
Pros of ECharts
- More comprehensive and diverse chart types, including 3D visualizations
- Better performance with large datasets due to canvas-based rendering
- Extensive customization options and theming capabilities
Cons of ECharts
- Steeper learning curve due to its extensive API and configuration options
- Larger file size, which may impact initial load times for web applications
Code Comparison
dc.js example:
var chart = dc.barChart("#chart");
chart
.dimension(dimension)
.group(group)
.x(d3.scale.ordinal())
.xUnits(dc.units.ordinal);
ECharts example:
var option = {
xAxis: { type: 'category', data: ['A', 'B', 'C'] },
yAxis: { type: 'value' },
series: [{ type: 'bar', data: [120, 200, 150] }]
};
chart.setOption(option);
Both libraries offer declarative ways to create charts, but ECharts uses a more configuration-based approach, while dc.js relies on method chaining. ECharts provides a single configuration object, whereas dc.js allows for more granular control through individual method calls.
dc.js is built on top of D3.js and focuses on creating interactive and interconnected charts for data exploration. It excels in creating dashboards with linked visualizations. ECharts, on the other hand, offers a wider range of chart types and is better suited for standalone, highly customizable visualizations with better performance for large datasets.
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
dc.js
Dimensional charting built to work natively with crossfilter rendered using d3.js.
NOTE: We are seeking new maintainers to join Deepak Kumar. See #1868 for discussion.
In dc.js, each chart displays an aggregation of some attributes through the position, size, and color of its elements, and also presents a dimension which can be filtered. When the filter or brush changes, all other charts are updated dynamically, using animated transitions.
Check out the example page and its annotated source for a quick five minute how-to guide. The detailed API reference is here (markdown version). For more examples and hints please visit the Wiki.
Support
- Example Site
- Changelog
- Frequently Asked Questions and Wiki
- v4.0 API Reference (markdown) (last - v3.1.9)
- dc.js on StackOverflow - ask questions and get help
- User Group ("mailing list") - discussion and longer topics
- GitHub Issues - bug reports and feature requests
Please direct questions and support requests to Stack Overflow or the user group. When posting to Stack Overflow, use the [dc.js]
and/or [crossfilter]
tags - other tags are likely to draw unwanted attention.
Get help faster with a working example! Fork these to get started:
blank jsFiddle - example jsFiddle - blank bl.ock - example bl.ock
Versioning
Version 4.* is compatible with d3 versions 4 and 5. It is not compatible with IE. Use dc.js 3.* if you need IE support, or use dc.js 2.* if you need compatibility with d3 version 3.
CDN location
https://unpkg.com/dc@4/dist/dc.js
https://unpkg.com/dc@4/dist/style/dc.css
or copy the latest links from CDNJS
Install with npm
npm install dc
Install without npm
Download
How to build dc.js locally
Prerequisite modules
Make sure the following packages are installed on your machine
- node.js
- npm
Install dependencies
$ npm install
Build and Test
$ grunt test
Developing dc.js
Start the development server
$ grunt server
- Jasmine specs are hosted at http://localhost:8888/spec
- The stock example is at http://localhost:8888/web
- More examples are at http://localhost:8888/web/examples
License
dc.js is an open source javascript library and licensed under Apache License v2.
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
📊 Re-usable, easy interface JavaScript chart library based on D3.js
Apache ECharts is a powerful, interactive charting and data visualization library for browser
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