Highcharts Gantt for Python
High-end Gantt chart visualization for the Python ecosystem
Todo
Add unit test / code coverage badges.
Highcharts Gantt for Python is an extension to the Highcharts Stock for Python library, providing a Python wrapper for the Highcharts Gantt JavaScript data visualization library.
Highcharts Gantt for Python also supports
Highcharts Core (JS) - the core Highcharts data visualization library
Highcharts Stock (JS) - the Highcharts extension providing time series and asset price data visualization
The Highcharts Export Server - enabling the programmatic creation of static (downloadable) data visualizations
In order to integrate Highcharts Gantt for Python into the Python ecosystem, the library also features native integration with:
Asana. Automatically generate Gantt charts from your Asana projects.
Monday.com. Automatically generate Gantt charts from your Monday.com boards.
JIRA. Automatically generate Gantt charts from your Jira projects.
Jupyter Labs/Notebook. You can now produce high-end and interactive Gantt charts using the full suite of Highcharts visualization capabilities.
Pandas. Automatically produce data visualizations from your Pandas dataframes
PySpark. Automatically produce data visualizations from data in a PySpark dataframe.
The Highcharts for Python Toolkit
The Highcharts Gantt for Python library is part of the broader Highcharts for Python Toolkit, which together provides comprehensive support across the entire Highcharts suite of data visualization libraries:
Python Library |
JavaScript Library |
Description |
---|---|---|
(this library) the core Highcharts data visualization library |
||
the time series visualization extension to Highcharts Core |
||
the map visualization extension to Highcharts Core |
||
Highcharts Gantt for Python |
the Gantt charting extension to Highcharts Core |
|
(all libraries in the Python toolkit) |
The Highcharts Export Server |
enabling the programmatic creation of static (downloadable) data visualizations |
Installation
To install Highcharts Gantt for Python, just execute:
$ pip install highcharts-gantt
Dependencies
Note
Highcharts Gantt for Python has several types of dependencies:
hard dependencies, without which you will not be able to use the library at all,
soft dependencies, which will not produce errors but which may limit the value you get from the library,
developer dependencies that contributors will need in their local environment, and
documentation dependencies that are necessary if you wish to generate (this) documentation
Warning
If these hard dependencies are not available in the environment where Highcharts Gantt for Python is running, then the library will simply not work. Besides Highcharts Gantt itself, all of the other hard dependencies are automatically installed when installing Highcharts Gantt for Python using:
$ pip install highcharts-gantt
Highcharts Gantt v.10.3 or higher
Note
Not technically a Python dependency, but obviously Highcharts Gantt for Python will not work properly if your rendering layer does not leverage Highcharts Gantt.
highcharts-stock v.1.0.0 or higher
esprima-python v.4.0 or higher
requests v.2.28 or higher
validator-collection v.1.5 or higher
Warning
If these soft dependencies are not available in the environment where
Highcharts Gantt for Python is running, then the library will throw a
HighchartsDependencyError
exception when
you try to use functionality that relies on them.
No error will be thrown until you try to use dependent functionality. So if you call
a from_pandas()
method but pandas is not
installed, you will get an error.
You can install Highcharts Gantt for Python with all soft dependencies using:
$ pip install highcharts-gantt[soft]
Warning
You will not be able to run unit tests without the Pytest test framework and a number of necessary extensions. To install the developer (and soft and documentation) dependencies, execute:
$ pip install highcharts-gantt[dev]
pytest v.7.1 or higher
pytest-cov v.3.0 or higher
pytest-xdist v.2.5 or higher
python-dotenv v. 0.21 or higher
Note
python-dotenv will fail silently if not available, as it will only leverage natural environment variables rather than a
.env
file in the runtime environment.pytz v.2022.1 or higher
tox v.4.0.0 or higher
Warning
You will not be able to generate documentation without Sphinx and a number of necessary extensions. To install the documentation dependencies, execute:
$ pip install highcharts-gantt[docs]
Sphinx v.6.1.3 or higher
Sphinx RTD Theme v.1.2 or higher
sphinx-tabs v.3.4.1 or higher
Sphinx Toolbox v.3.4 or higher
Why Highcharts for Python?
Highcharts is the world’s most popular, most powerful, category-defining JavaScript data visualization library. If you are building a web or mobile app/dashboard that will be visualizing data in some fashion, you should absolutely take a look at the Highcharts suite of solutions. Take a peak at some Highcharts Gantt demo visualizations.
As a suite of JavaScript libraries, Highcharts is written in JavaScript, and is used to configure and render data visualizations in a web browser (or other JavaScript-executing) environment. As a set of JavaScript libraries, its audience is JavaScript developers. But what about the broader ecosystem of Python developers and data scientists?
Given Python’s increasing adoption as the technology of choice for data science and for the backends of leading enterprise-grade applications, Python is often the backend that delivers data and content to the front-end…which then renders it using JavaScript and HTML.
There are numerous Python frameworks (Django, Flask, Tornado, etc.) with specific capabilities to simplify integration with Javascript frontend frameworks (React, Angular, VueJS, etc.). But facilitating that with Highcharts has historically been very difficult. Part of this difficulty is because the Highcharts JavaScript suite - while supporting JSON as a serialization/deserialization format - leverages JavaScript object literals to expose the full power and interactivity of its data visualizations. And while it’s easy to serialize JSON from Python, serializing and deserializing to/from JavaScript object literal notation is much more complicated.
This means that Python developers looking to integrate with Highcharts typically had to either invest a lot of effort, or were only able to leverage a small portion of Highcharts’ rich functionality.
So we wrote the Highcharts for Python Toolkit to bridge that gap.
The Highcharts for Python Toolkit provides Python object representation for all of the JavaScript objects defined in the Highcharts (JavaScript) API. It provides automatic data validation, and exposes simple and standardized methods for serializing those Python objects back-and-forth to JavaScript object literal notation.
Highcharts Gantt for Python provides support for the Highcharts Gantt extension, which is designed to provide extensive capabilities optimized for project, time, and resource allocation data visualization with robust interactivity. For ease of use, it also includes the full functionality of Highcharts Stock for Python and Highcharts Core for Python.
Key Highcharts Gantt for Python Features
Clean and consistent API. No reliance on “hacky” code,
dict
and JSON serialization, or impossible to maintain / copy-pasted “spaghetti code”.Comprehensive Highcharts support. Every single Highcharts chart type and every single configuration option is supported in Highcharts Gantt for Python. This includes:
the over 70 data visualization types supported by Highcharts Core,
the 50+ visualizations supported by Highcharts Stock
the multiple Gantt visualizations available in Highcharts Gantt
all with full support for the rich JavaScript formatter (JS callback functions) capabilities that are often needed to get the most out of Highcharts’ visualization and interaction capabilities.
See also
Simple JavaScript Code Generation. With one method call, produce production-ready JavaScript code to render your interactive visualizations using Highcharts’ rich capabilities.
Easy Chart Download. With one method call, produce high-end static visualizations that can be downloaded or shared as files with your audience. Produce static charts using the Highsoft-provided Highcharts Export Server, or using your own private export server as needed.
Integration with Asana, Monday.com, and Jira. Your project data likely lives in a modern project management platform like Asana, Monday.com, or Atlassian JIRA. You can easily pull data from those platforms into your Highcharts Gantt visualizations using one method call.
Integration with Pandas and PySpark. With two lines of code, produce a high-end interactive visualization of your Pandas or PySpark dataframe.
Consistent Code Style. For Python developers, switching between Pythonic code conventions and JavaScript code conventions can be…annoying. So Highcharts for Python applies Pythonic syntax with automatic conversion between Pythonic
snake_case
notation and JavaScriptcamelCase
styles.
Highcharts Gantt for Python vs Alternatives
Since Highcharts Gantt is one of the most popular high-end Gantt visualization libraries for JavaScript, there are a variety of alternative ways of working with it in Python. We have an obvious bias towards Highcharts Gantt for Python, but it may be useful to compare it against some commonly-used alternatives:
By far, this is the most common approach to integrating Highcharts into your Python code. As a developer, you know that your JavaScript front-end will be using Highcharts Gantt (JS). So you work in your Python backend to deliver the data to your front-end that your front-end will need.
There are many patterns for rolling your own Highcharts + Python implementation, but the patterns we have seen most often include:
Your Python code is “hands off” - it does not touch any data visualization configuration or manipulation. All of that gets handled in your JavaScript front-end code.
This approach is very “clean” from a code architecture standpoint. However, in practice it often problematic because it delegates data manipulation and (potentially) business logic handling to your front-end code. Depending on the overall design of your software, it can make your code harder to maintain. Furthermore, depending on your team composition, it may simply be impractical for your team.
Your Python code constructs a JSON object (typically by serializing a Python
dict
to JSON) which gets delivered to your JavaScript front-end,
which then hands the JSON code off to Highcharts to visualize.
This approach is also fairly clean. JSON, after all, is easy in both Python and JavaScript. But JSON is a suboptimal transport mechanism for some of Highcharts’ most powerful features: callback functions. As this is native JavaScript code, they cannot really be serialized securely to JSON and then executed directly by the Highcharts library. So while simple use cases can be handled through JSON serialization, many more robust or sophisticated uses of Highcharts (which would rely on formatters, event handling, etc.) will simply not work.
The most sophisticated implementations we have seen actually replicate much of the functionality of the Highcharts for Python Toolkit, where they construct JavaScript object literal notation serialization and de-serialization for their robust use cases.
This approach is the most robust of all custom implementations, for obvious reasons. However, as with any full-fledged custom implementation your mileage may vary. For the most sophisticated Highcharts + Python applications that we have seen, this has been the approach of choice because it eliminates all of the limitations of the other approaches mentioned.
But, to create custom serialization on a one-off/custom basis can take a large amount of effort. Constructing a comprehensive solution like the Highcharts for Python Toolkit is deeply non-trivial, and so we think it’s wiser to use a toolkit where:
the implementation/heavy lifting has been done for you
you are guaranteed ongoing maintenance
you are guaranteed available support
In many cases, particularly when working with data science teams who are data scientists first and software developers by necessity, the team traditionally turns to weaker data visualization packages simply because those packages are available in Python.
This option has historically - sadly - been fairly common, and is one of the primary reasons for our development of the Highcharts for Python Toolkit. Even though plenty of developers coming to Python from the JavaScript ecosystem ask “Why can’t we just use Highcharts?”, many in the Python ecosystem will answer “because it’s a pain to do”. So they turn to Highcharts alternatives that are are more limited but more Python-friendly.
Tip
When to use it?
In practice, we find that rolling our own solution is great when doing a limited number of simple and static (non-interactive) visualizations. Then you can just quickly use some simple JSON serialization, and rapidly get a high-quality chart visualized cleanly using Highcharts. But anything more robust than that is going to prove “hacky” and incredibly difficult to maintain.
Which is why we created the Highcharts for Python Toolkit in the first place, so that:
you gain the ability to use as much or as little of Highcharts rich functionality as you need
you get native integration with key Python ecosystem members “out of the box”
you don’t have to worry about maintaining the “glue” code connecting your Python implementation with Highcharts (JS)
you have support available when you need it
The panel-highcharts library is - honestly - fantastic. It is a excellent wrapper for the Highcharts (JS) suite to enable exploratory data analysis (EDA) in Jupyter Notebooks or in Holoviz web applications.
There are really two limitations to be aware of:
It relies on the Jupyter Labs/Notebook or Holoviz context, which means that it would be hard to utilize unless you happen to be working in Jupyter or Holoviz.
It relies on configuration via
dict
objects that map 1:1 to the Highcharts API. In practice, this forces the developer to switch between Pythonicsnake_case
convention and JavaScriptcamelCase
conventions within the same code. Not a big problem, but annoying.To really benefit from its capabilities, it requires a fair bit of Holoviz boilerplate and widget configuration, which can be complicated, verbose, and “fiddly”.
Tip
When to use it?
If your use case is limited to highly-interactive exploratory data analysis in a Jupyter Labs/Notebook environment and you are willing to construct some complicated Holoviz widget configuration code, it may be worth considering this library.
However, those are some pretty specific gating conditions. For integration with a non-Jupyter application? That’s not what the Highcharts for Python Toolkit was designed for.
The python-highcharts library is a great start to working with Highcharts in the Python ecosystem. However, given that its last release was in December 2018, it can best be considered “stale” and “impractical”.
While the design of this library is an excellent start, and in some ways served as an inspiration for the Highcharts for Python Toolkit, it is not a practical solution for several key reasons:
“Stale” / Unmaintained? The last commit to the library was in 2018, almost four years ago (as of the time of writing).
Not comprehensive. The library is not comprehensive relative to the Highcharts API, and does not support many of the features and chart types introduced over the last several years. Not all Highcharts chart types and classes are supported, and not all Highcharts functionality is available.
JavaScript-forward style. The library relies heavily on Python
dict
objects but relying on the JavaScript style for naming conventions. This is not that big of a deal, but when building complex applications in Python it can be annoying to constantly context-switch from Pythonsnake_case
standards to JavaScriptcamelCase
style.
Tip
When to use it?
We wouldn’t rely heavily on it, as it no longer seems to be maintained, has fallen out of alignment with more recent releases of the Highcharts suite and its functionality is (by design) not comprehensive.
The PyHighcharts library is closest in philosophy to the Highcharts for Python Toolkit, but it is also much more limited than any of the other alternatives discussed:
Dead library. This library hasn’t seen any new releases since 2015. There’s an open question whether it will even import / work in modern versions of Python (we haven’t tested it meaningfully in the last couple of years).
Extremely limited support. By design, this library only supports a handful of the visualizations offered by Highcharts (JS). Furthermore, even for those visualization types, only a limited number of configuration options are available. And because the library has not been updated in about seven years, there’s an open question whether it will even work to produce relevant visualizations.
Tip
When to use it?
We wouldn’t. While you might still be able to use the other alternatives listed, this is one that we would not recommend be touched under any circumstances.
Hello World, and Basic Usage
1. Import Highcharts Gantt for Python
Tip
Best Practice!
This method of importing Highcharts Gantt for Python objects yields the fastest
performance for the import
statement. However, it is more verbose and requires
you to navigate the extensive Highcharts Gantt for Python API.
# Import classes using precise module indications. For example:
from highcharts_gantt.chart import Chart
from highcharts_gantt.global_options.shared_options import SharedGanttOptions
from highcharts_gantt.options import HighchartsGanttOptions
from highcharts_gantt.options.plot_options.gantt import GanttOptions
from highcharts_gantt.options.series.gantt import GanttSeries
Caution
This method of importing Highcharts Gantt for Python classes has relatively slow performance because it imports hundreds of different classes from across the entire library. This performance impact may be acceptable to you in your use-case, but do use at your own risk.
# Import objects from the catch-all ".highcharts" module.
from highcharts_gantt import highcharts
# You can now access specific classes without individual import statements.
highcharts.Chart
highcharts.SharedGanttOptions
highcharts.HighchartsGanttOptions
highcharts.GanttOptions
highcharts.GanttSeries
2. Create Your Chart
# from a JavaScript file my_chart = highcharts.Chart.from_js_literal('my_js_literal.js') # from a JSON file my_chart = highcharts.Chart.from_json('my_json.json') # from a Python dict my_chart = highcharts.Chart.from_dict(my_dict_obj) # from Asana my_chart = highcharts.Chart.from_asana(project_gid = MY_ASANA_PROJECT_ID) # from Monday.com my_chart = highcharts.Chart.from_monday(board_id = MY_MONDAY_BOARD_ID) # from JIRA my_chart = highcharts.Chart.from_jira(project_id = MY_JIRA_PROJECT_KEY) # from a Pandas dataframe my_chart = highcharts.Chart.from_pandas(df, property_map = { 'x': 'transactionDate', 'y': 'invoiceAmt', 'id': 'id' }, series_type = 'line') # from a PySpark dataframe my_chart = highcharts.Chart.from_pyspark(df, property_map = { 'x': 'transactionDate', 'y': 'invoiceAmt', 'id': 'id' }, series_type = 'line') # from a CSV my_chart = highcharts.Chart.from_csv('/some_file_location/filename.csv' column_property_map = { 'x': 0, 'y': 4, 'id': 14 }, series_type = 'line') # from a HighchartsOptions configuration object my_chart = highcharts.Chart.from_options(my_options) # from a Series configuration my_chart = highcharts.Chart.from_series(my_series)
3. Configure Global Settings (optional)
# Import SharedGanttOptions from highcharts_gantt.global_options.shared_options import SharedGanttOptions # from a JavaScript file my_global_settings = SharedGanttOptions.from_js_literal('my_js_literal.js') # from a JSON file my_global_settings = SharedGanttOptions.from_json('my_json.json') # from a Python dict my_global_settings = SharedGanttOptions.from_dict(my_dict_obj) # from a HighchartsOptions configuration object my_global_settings = SharedGanttOptions.from_options(my_options)
4. Configure Your Chart / Global Settings
from highcharts_gantt.options.title import Title from highcharts_gantt.options.credits import Credits # Using dicts my_chart.title = { 'align': 'center' 'floating': True, 'text': 'The Title for My Chart', 'use_html': False, } my_chart.credits = { 'enabled': True, 'href': 'https://www.highcharts.com/', 'position': { 'align': 'center', 'vertical_align': 'bottom', 'x': 123, 'y': 456 }, 'style': { 'color': '#cccccc', 'cursor': 'pointer', 'font_size': '9px' }, 'text': 'Chris Modzelewski' } # Using direct objects from highcharts_gantt.options.title import Title from highcharts_gantt.options.credits import Credits my_title = Title(text = 'The Title for My Chart', floating = True, align = 'center') my_chart.options.title = my_title my_credits = Credits(text = 'Chris Modzelewski', enabled = True, href = 'https://www.highcharts.com') my_chart.options.credits = my_credits
5. Generate the JavaScript Code for Your Chart
Now having configured your chart in full, you can easily generate the JavaScript code that will render the chart wherever it is you want it to go:
# as a string js_as_str = my_chart.to_js_literal() # to a file (and as a string) js_as_str = my_chart.to_js_literal(filename = 'my_target_file.js')
6. Generate the JavaScript Code for Your Global Settings (optional)
# as a string global_settings_js = my_global_settings.to_js_literal() # to a file (and as a string) global_settings_js = my_global_settings.to_js_literal('my_target_file.js')
7. Generate a Static Version of Your Chart
# as in-memory bytes my_image_bytes = my_chart.download_chart(format = 'png') # to an image file (and as in-memory bytes) my_image_bytes = my_chart.download_chart(filename = 'my_target_file.png', format = 'png')
Getting Help/Support
The Highcharts for Python toolkit comes with all of the great support that you are used to from working with the Highcharts JavaScript libraries. When you license the toolkit, you are welcome to use any of the following tools to get help using the toolkit. In particular, you can:
Use the Highcharts Forums
Use Stack Overflow with the
highcharts-for-python
tagReport bugs or request features in the library’s Github repository
File a support ticket with us
FOR MORE INFORMATION: https://www.highchartspython.com/get-help
Contributing
We welcome contributions and pull requests! For more information, please see the Contributor Guide. And thanks to all those who’ve already contributed:
Chris Modzelewski (@hcpchris / @insightindustry)
Testing
We use TravisCI for our build automation and ReadTheDocs for our documentation.
Detailed information about our test suite and how to run tests locally can be found in our Testing Reference.