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
Apache ECharts is a powerful, interactive charting and data visualization library for browser
Multi-Dimensional charting built to work natively with crossfilter rendered with d3.js
Quick Overview
NVD3 is a reusable charting library for d3.js. It provides a higher-level framework for building interactive charts and graphs using D3's powerful data visualization capabilities. NVD3 aims to simplify the process of creating common chart types while still allowing for customization and extensibility.
Pros
- Easy to use with pre-built chart components
- Highly customizable and extensible
- Responsive and interactive charts out of the box
- Good documentation and examples
Cons
- Not actively maintained (last commit was in 2019)
- Limited chart types compared to more modern libraries
- Performance issues with large datasets
- Some bugs and inconsistencies across different chart types
Code Examples
- Creating a simple line chart:
nv.addGraph(function() {
var chart = nv.models.lineChart()
.x(function(d) { return d[0] })
.y(function(d) { return d[1] })
.useInteractiveGuideline(true);
d3.select('#chart svg')
.datum(data)
.transition().duration(500)
.call(chart);
return chart;
});
- Creating a multi-bar chart:
nv.addGraph(function() {
var chart = nv.models.multiBarChart()
.reduceXTicks(true)
.rotateLabels(0)
.showControls(true)
.groupSpacing(0.1);
d3.select('#chart svg')
.datum(data)
.call(chart);
return chart;
});
- Creating a pie chart:
nv.addGraph(function() {
var chart = nv.models.pieChart()
.x(function(d) { return d.label })
.y(function(d) { return d.value })
.showLabels(true);
d3.select("#chart svg")
.datum(data)
.transition().duration(350)
.call(chart);
return chart;
});
Getting Started
- Include D3.js and NVD3 in your HTML:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.6/nv.d3.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.6/nv.d3.min.js"></script>
- Create a container for your chart:
<div id="chart">
<svg></svg>
</div>
- Use JavaScript to create and render the chart (see code examples above).
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, allowing for highly customized visualizations
- Larger community and ecosystem, with extensive documentation and examples
- Regularly updated with new features and improvements
Cons of D3
- Steeper learning curve, requiring more time to master
- Lower-level API, necessitating more code for basic charts
Code Comparison
NVD3 (simplified bar chart):
nv.addGraph(function() {
var chart = nv.models.discreteBarChart();
d3.select('#chart svg').datum(data).call(chart);
return chart;
});
D3 (simplified bar chart):
const svg = d3.select("svg");
svg.selectAll("rect")
.data(data)
.enter().append("rect")
.attr("x", (d, i) => i * 30)
.attr("y", d => height - d * 4)
.attr("width", 25)
.attr("height", d => d * 4);
NVD3 provides a higher-level API for common chart types, making it easier to create standard visualizations with less code. D3, on the other hand, offers more granular control over every aspect of the visualization, allowing for more complex and customized charts at the cost of increased complexity.
Simple HTML5 Charts using the <canvas> tag
Pros of Chart.js
- Lighter weight and faster rendering compared to NVD3
- More extensive documentation and active community support
- Easier to customize and extend with plugins
Cons of Chart.js
- Less built-in chart types compared to NVD3
- Limited support for large datasets and real-time updates
Code Comparison
NVD3:
nv.addGraph(function() {
var chart = nv.models.lineChart()
.margin({left: 100})
.useInteractiveGuideline(true)
.transitionDuration(350)
.showLegend(true)
.showYAxis(true)
.showXAxis(true);
d3.select('#chart svg')
.datum(data)
.call(chart);
return chart;
});
Chart.js:
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
type: 'line',
data: data,
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
title: {
display: true,
text: 'Chart.js Line Chart'
}
}
}
});
Both libraries offer powerful charting capabilities, but Chart.js provides a more modern and lightweight approach with easier customization. NVD3, built on D3.js, offers more complex visualizations out of the box but may have a steeper learning curve.
Open-source JavaScript charting library behind Plotly and Dash
Pros of plotly.js
- More extensive and diverse chart types, including 3D visualizations
- Active development with frequent updates and new features
- Supports both static and interactive plots
Cons of plotly.js
- Larger file size, which may impact page load times
- Steeper learning curve due to more complex API
- Some advanced features require a commercial license
Code Comparison
NVD3 example:
nv.addGraph(function() {
var chart = nv.models.lineChart();
d3.select('#chart svg')
.datum(data)
.call(chart);
return chart;
});
plotly.js example:
Plotly.newPlot('chart', [{
x: [1, 2, 3, 4],
y: [10, 15, 13, 17],
type: 'scatter'
}], {
title: 'Simple Line Chart'
});
Both libraries offer declarative ways to create charts, but plotly.js provides a more concise syntax for basic plots. NVD3 relies more heavily on D3.js conventions, while plotly.js has a more self-contained API. plotly.js offers more customization options out-of-the-box, but this can also make it more complex for simple use cases.
Highcharts JS, the JavaScript charting framework
Pros of Highcharts
- More extensive documentation and examples
- Wider range of chart types and customization options
- Better browser compatibility, including older versions
Cons of Highcharts
- Commercial license required for most use cases
- Larger file size, potentially impacting page load times
- Steeper learning curve due to more complex API
Code Comparison
NVD3:
nv.addGraph(function() {
var chart = nv.models.lineChart();
d3.select('#chart svg')
.datum(data)
.call(chart);
return chart;
});
Highcharts:
Highcharts.chart('container', {
series: [{
data: [1, 2, 3, 4, 5]
}]
});
Both libraries offer declarative ways to create charts, but Highcharts generally requires less code for basic implementations. NVD3 leverages D3.js, providing more low-level control but potentially requiring more setup.
NVD3 is open-source and free to use, while Highcharts requires a license for commercial use. Highcharts offers more out-of-the-box features and chart types, but NVD3 provides greater flexibility for custom visualizations through its D3.js foundation.
Choose NVD3 for open-source projects or highly customized visualizations. Opt for Highcharts when you need a wide range of chart types, extensive documentation, and strong browser compatibility, and can accommodate the licensing costs.
Apache ECharts is a powerful, interactive charting and data visualization library for browser
Pros of ECharts
- More comprehensive and feature-rich, offering a wider variety of chart types and customization options
- Better performance with large datasets, especially for rendering and animations
- Stronger support for responsive design and mobile devices
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
- Less integration with specific frameworks like Angular or React out of the box
Code Comparison
ECharts:
var myChart = echarts.init(document.getElementById('main'));
var option = {
xAxis: {type: 'category', data: ['A', 'B', 'C']},
yAxis: {type: 'value'},
series: [{type: 'bar', data: [1, 2, 3]}]
};
myChart.setOption(option);
NVD3:
nv.addGraph(function() {
var chart = nv.models.discreteBarChart();
d3.select('#chart svg')
.datum([{key: "Cumulative Return", values: [{x: "A", y: 1}, {x: "B", y: 2}, {x: "C", y: 3}]}])
.call(chart);
return chart;
});
Multi-Dimensional charting built to work natively with crossfilter rendered with d3.js
Pros of dc.js
- Built on top of Crossfilter, enabling fast multi-dimensional filtering and grouping
- Provides a rich set of chart types with built-in interactivity and data linking
- Offers seamless integration with other D3-based visualizations
Cons of dc.js
- Steeper learning curve due to its reliance on Crossfilter concepts
- Less flexibility in customizing chart appearance compared to NVD3
- Smaller community and fewer examples available online
Code Comparison
dc.js:
var chart = dc.pieChart("#chart");
chart
.dimension(dimension)
.group(group)
.width(300)
.height(300)
.render();
NVD3:
nv.addGraph(function() {
var chart = nv.models.pieChart()
.x(function(d) { return d.key })
.y(function(d) { return d.y });
d3.select("#chart svg")
.datum(data)
.call(chart);
return chart;
});
Both libraries offer declarative ways to create charts, but dc.js leverages Crossfilter for data manipulation, while NVD3 focuses more on chart customization and styling options.
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
NVD3 - A reusable D3 charting library
Inspired by the work of Mike Bostock's Towards Reusable Charts, and supported by a combined effort of Novus and the NVD3 community.
View Examples | NEW Documentation! | Development build status:
Usage
Simply add the nv.d3
assets to your project and include them in your HTML.
<link href="nv.d3.min.css" rel="stylesheet">
<script src="nv.d3.min.js"></script>
nv.d3.js
should appear afterd3.js
is included.- Prefer minified assets (
.min
) for production.
Dependencies
NVD3 is recommended to go with d3.js version 3.5.3 and later, but NOT d3 4.x yet. version 3.5.17 is the most recent d3 v3 release.
Minimum D3 version required: 3.4.4
For a D3v4 Version, see the work in progress at the nvd3 organization
Along with pieChart
options padAngle
and cornerRadius
, the interactive guideline tooltip now requires these later versions of D3 (3.4.4+, specifically, to get interactive tooltips). The interactive guide lines rely on the more recent d3.bisector()
method which treats accessors taking two parameters (the second being the element index) as comparators (see d3.bisector()).
Supported Browsers
NVD3 runs best on WebKit based browsers.
- Google Chrome: latest version
- Opera 15+ (i.e. webkit version)
- Safari: latest version
- Firefox: latest version
- Internet Explorer: 10+
Do we support D3 v4.x?
No, we do not... we are very interested in taking this on but could use some help. Please let us know if you'd like to help make this a reality! :)
Changelog
1.8.6 Changes:
- Community bugfixes
1.8.5 Changes:
- Community bugfixes
- New force-directed graph
1.8.4 Changes:
- Community bugfixes including tooltip fixes.
1.8.3 Changes:
- Lots of community bugfixes
- Added force-directed chart
1.8.2 Changes:
- Lots of community bugfixes and a few extra minor features
1.8.1 Changes:
- Tooltips were refactored - If you have customized your tooltips, note that you may need to adjust your custom functions as the data passed has changed format. See the new tooltip options for more details.
- Added boxplot charts | example
- Added candlestick charts | example
- Added extra donut chart abilities | examples
- Added sunburst Charts | example
- Time Series | example
- Another legend format available | example
- Lots of bug fixes (see closed issues)
- (for all examples, see here)
1.7.1 Changes:
- Fixed axis.staggerLabels bug.
- Fixed Karma unit tests.
- Fixed chart test pages.
- Merged in nvd3-community changes and development branch.
1.7.0 Changes:
- Fixes around 20 small bugs.
- Fixed the notorious slowness of line charts and scatter plots on chrome
- Combined the scatterChart and scatterChartWithLines models
- Combined the linePlusBarChart and linePlusBarChartWithFocus models.
- renamed some of the options (see the new documentation for what options are available for each chart)
- Completed the migration of the option functions to an object format which allows the generation of the documentation in an automated way. Not everything has a description yet, but check it out!
- Added extra options to the donut charts based on features that will be in d3 3.5. The donut example page loads the latest d3 from their 3.5 branch so keep that in mind.
- Added an example of the parallelCoordinates chart.
- Fixed up the half-done OHLC bar chart, and made an example for it as well.
1.6.0 Changes:
- includes about a dozen bug fixes and pull requests I fixed and merged in from the issues/pulls from the original project.
- It also standardized all indention
Current development focus
- Review outstanding pull requests and issues.
- Try to find an easy way to actually document usage and all chart options.
- Improve the testing framework.
- Setup continuous integration.
Bugs
Found a bug? Check out the latest from the master
branch and make sure it's not already fixed first! If you don't see a related fix, please open an issue.
Optional dependencies
Including Fastdom in your project can greatly increase the performance of the line chart (particularly in Firefox and Internet Explorer) by batching DOM read and write operations to avoid layout thrashing. NVD3 will take advantage of Fastdom if present.
Contributing
If one of the existing models doesn't meet your needs, fork the project, implement the model and an example using it, send us a pull request, for consideration for inclusion in the project.
If you'd like to contribute consistently, show me what you've got with some good pull requests and you may get added to the nvd3-community org!
A few rules for pull requests
- Please commit to the
master
branch - Do NOT check in anything under the
build
directory, it clutters up the commit and just gets overwritten later. - All new features must come with unit test coverage
- Bug fixes should come with unit tests that prove their fix
If you want to test your changes using the example pages,
you'll have to run grunt production
to build the items into the build
directory.
You must do this before your changes show up in the examples, as they link to the build directory
in order to properly show off the finished product.
Please remember to NOT include the build files in your commit though,
only include the source files you changed!
Tips for Testing
- Unit tests were written in Karma and Mocha. Follow instructions in Building Latest to get npm packages setup. This may not work on Windows machines.
- Run
bower install
to get bower dependencies. - Run
grunt
to start the unit tests. - Also visually inspect the HTML pages in the examples/ and test/ folders. Make sure there are no glaring errors.
- Novus now uses Travis CI for continuous integration. Visit our travis build page to see the latest status.
Meteor Tinytests
- Any Meteor-specific features can be tested from the command line using
tinytest
and Spacejam spacejam
can be installed by runningnpm install -g spacejam
.- Tinytests can then be executed by running
spacejam test-packages ./
from this project's root.
Building latest
- First clone the repository and checkout the
master
branch - make sure
nodejs
is installed via your system's package manager. - Install
grunt
,grunt-cli
, andbower
:npm install -g grunt grunt-cli bower
have node download nvd3's required modules with:
npm install
build with:
grunt production
You should now have a build
directory with the js and css files within.
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
Apache ECharts is a powerful, interactive charting and data visualization library for browser
Multi-Dimensional charting built to work natively with crossfilter rendered with d3.js
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