{"id":3249,"library":"python-nvd3","title":"Python NVD3","description":"Python NVD3 is a Python wrapper for the NVD3 JavaScript library, which in turn builds re-usable charts and chart components for d3.js. It enables Python developers to generate interactive D3.js charts by writing Python code. The current version, 0.16.0, was uploaded to PyPI in April 2024. While receiving recent maintenance uploads, major feature development largely concluded around 2015, indicating a maintenance-focused release cadence.","status":"maintenance","version":"0.16.0","language":"en","source_language":"en","source_url":"https://github.com/areski/python-nvd3","tags":["charting","data visualization","d3.js","nvd3","python","javascript"],"install":[{"cmd":"pip install python-nvd3","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for generating URL-friendly slugs for chart names/IDs.","package":"python-slugify","optional":false},{"reason":"Used for rendering the JavaScript and HTML templates for the charts.","package":"jinja2","optional":false},{"reason":"The core JavaScript library for data visualization, required at runtime in the browser for charts to render. Needs to be served separately (e.g., via CDN or local files).","package":"d3.js","optional":false},{"reason":"The JavaScript charting library built on D3.js, required at runtime in the browser for charts to render. Needs to be served separately.","package":"nvd3.js","optional":false},{"reason":"Historically recommended for managing D3.js and NVD3.js JavaScript dependencies, though not strictly mandatory if JS files are managed otherwise.","package":"bower","optional":true}],"imports":[{"symbol":"pieChart","correct":"from nvd3 import pieChart"},{"symbol":"lineChart","correct":"from nvd3 import lineChart"},{"symbol":"multiBarChart","correct":"from nvd3 import multiBarChart"}],"quickstart":{"code":"from nvd3 import pieChart\n\n# Prepare data\nxdata = [\"Orange\", \"Banana\", \"Pear\", \"Kiwi\", \"Apple\", \"Strawberry\", \"Pineapple\"]\nydata = [3, 4, 0, 1, 5, 7, 3]\n\n# Create a pie chart\nchart_name = 'pieChart'\nchart = pieChart(name=chart_name, color_category='category20c', height=450, width=450)\n\n# Add a series of data\nextra_serie = {\"tooltip\": {\"y_start\": \"\", \"y_end\": \" cal\"}}\nchart.add_serie(y=ydata, x=xdata, extra=extra_serie)\n\n# Build the HTML content\nchart.buildcontent()\n\n# The generated HTML can be saved to a file or embedded in a web application\nhtml_output = f\"\"\"\n<!DOCTYPE html>\n<html>\n<head>\n    <title>NVD3 Pie Chart</title>\n    <!-- You MUST include D3.js and NVD3.js libraries -->\n    <!-- For local testing, download from nvd3.org/bower_components/ -->\n    <script src=\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js\" charset=\"utf-8\"></script>\n    <script src=\"https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.6/nv.d3.min.js\" charset=\"utf-8\"></script>\n    <link href=\"https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.6/nv.d3.min.css\" rel=\"stylesheet\" type=\"text/css\">\n    <style>\n        svg { font: 10px sans-serif; }\n    </style>\n</head>\n<body>\n    <h2>{chart_name}</h2>\n    {chart.htmlcontent}\n</body>\n</html>\n\"\"\"\n\n# In a real application, you might pass this 'html_output' to a web framework template.\nprint(html_output)\n\n# To demonstrate the generated chart in a browser, uncomment the following:\n# with open('my_pie_chart.html', 'w') as f:\n#     f.write(html_output)\n# import webbrowser\n# webbrowser.open('my_pie_chart.html')","lang":"python","description":"This quickstart demonstrates how to create a basic pie chart using `python-nvd3`. It initializes a `pieChart` object, adds data, builds the HTML and JavaScript content, and shows how to generate a complete HTML file ready for rendering in a web browser. Note that D3.js and NVD3.js JavaScript libraries, along with their CSS, must be included externally for the chart to render properly."},"warnings":[{"fix":"Include `<script>` tags for `d3.min.js` and `nv.d3.min.js`, and a `<link>` tag for `nv.d3.min.css` in your HTML, pointing to either a CDN or locally served files.","message":"The `python-nvd3` library primarily generates HTML and JavaScript code. It does NOT bundle or serve the D3.js and NVD3.js JavaScript libraries themselves. Users must ensure these external JS/CSS assets are available to the browser (e.g., via CDN links or by serving local files) for the charts to display.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Convert `datetime` objects or seconds since epoch to milliseconds since epoch before passing them to the chart data. E.g., `int(time.mktime(dt_object.timetuple()) * 1000)`.","message":"When working with time-series data for charts like `lineChart`, NVD3 expects time values to be represented as milliseconds since the Unix epoch, not seconds or `datetime` objects directly. Incorrect formatting will lead to misrendered or empty charts.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `chart.add_serie(y=ydata, x=xdata, name='Series Name')`.","message":"The method to add a data series to a chart is `add_serie` (singular 'serie'), not the commonly mistaken `add_series` (plural). Using the plural form will result in an `AttributeError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Update to a newer version of the library or manually ensure correct (absolute or CDN) paths are used for the JavaScript and CSS dependencies in the generated HTML.","message":"Older versions of `python-nvd3` might generate HTML with relative paths to D3.js and NVD3.js assets. If these assets are not located in the expected relative directories, the browser will encounter 404 errors, and charts will not render.","severity":"deprecated","affected_versions":"< 0.15.0 (and potentially others depending on specific generation settings)"},{"fix":"Review the GitHub repository's commit history and issue tracker to understand the current development status and decide if the library meets your project's longevity and feature requirements.","message":"While PyPI shows a recent upload for version 0.16.0, the project's core feature development appears to have largely slowed down around 2015. Newer versions primarily reflect minor fixes or compatibility updates rather than significant new chart types or functionality. Users seeking actively developed, modern charting libraries might consider alternatives.","severity":"gotcha","affected_versions":"0.15.0 and higher"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}