While working on Cube.js, we’re seeing a lot of different visualization libraries. Given that Cube.js provides an API layer for analytics on top of an SQL database and doesn’t play on the visualization field, any charting library can be used to build dashboards with it. That’s why we’re always on a search for a nice and developer-friendly visualization library.
The list below is for React-specific libraries. I’ll try to build almost the same stacked bar chart with axes formatting, legend and tooltip using every one of it. For the data backend, we’ll use Cube.js hosted on Heroku. I’ll also use Cube.js React binding, which uses the render props technique and doesn’t render anything itself, letting us build whatever we want with any charting library.
Along the way, I’ll also use two very handy libraries—moment.js
and numeral.js
for dates and numbers formatting, respectively.
As a data input, we are going to use the resultSet.chartPivot() method from the Cube.js Javascript client. It returns an array of data, and in our case, it looks like this:
Now, let’s jump to the list.
If you don’t see your favorite library or just want me to add one more—just ping me in this Public Slack Community. I’m happy to add as many libraries as I can to the list.
Recharts
Recharts provides a set of modular charting components and does a great job by letting you mix those components together to easily build things like a composed line and bar chart.
It is the most popular library to date. It has more than 11k stars on Github, but a huge number (600 to date) of open issues as well.
The documentation is quite extensive but lacks details in some parts. You can find a bunch of examples at Rechart’s website, which could be a good starting point to building your own charts.
Recharts has a bunch of options for customization. Besides that, it allows low-level customization via custom SVG elements.
Here is how to build our stacked bar chart in Recharts:
In this and all the following examples I'm using colors
, dateFormatter
, and numberFormatter
variables. Here is how they are defined:
Victory
Victory follows the same composable pattern as Recharts. It is developed by Formidable, which has other solid open-source libraries besides Victory as well. It is the only library on the list that also works with React Native.
It’s the second most popular library after Recharts with more than 7K stars on Github, but has 5 times less open issues than Recharts. Victory has a community chat on Spectrum.
It is well documented and has an examples gallery.
Victory comes with two themes: grayscale and material, and allows you to create customer themes to have a consistent look across all the charts.
Below you can see the code for our stacked bar chart with Victory:
Nivo
As well as Recharts and Victory, Nivo is built on top of D3 and is React-specific. But unlike previous libraries it is not composable. It provides one component per chart type and this component is configured via multiple props. Nivo is distributed as a set of packages for specific chart types, for example, @nivo/bar
. So, one needs to install a specific package to use a specific chart type.
The project itself is quite active; it has more than 5k stars on Github and almost 300 members in the community chat.
It has interactive documentation, where you can build config for your chart. Although it is nice, It lacks a good old text API reference and search option. It also has a Storybook with examples. It helped me a lot to shortcut the time to build the first chart. Same as Victory, Nivo lets you create your own theme to have a consistent look across all the charts.
We’re going to use the @nivo/bar
package for our stack bar chart; you can find a code sample and CodeSandbox demo below.
BizCharts
BizCharts is React-specific visualization library based on G2, a visualization grammar. It is backed by Alibaba and plays nicely with Ant Design Framework.
It has almost 4k stars on Github, but the majority of development is in Chinese, same for most of the documentation. I think the team is doing a great job of translating the docs, but it is still a work in progress.
Though, it lacks documentation in English the API is pretty straightforward. The only hard thing is to re-format the data into the specific format for the stacked chart.
React-vis
React-vis is being developed by Uber and seems quite active with 5.4k Github stars, 150 open issues, and a lot of recent commits. It is modular, like most of the libraries on the list. It comes with some nice default styles, which should be imported separately as CSS files.
Same as Nivo, it has Storybook with examples. The components API is also well documented. On the customization side you can control the look and feel via custom CSS styles. React-vis also provides a specific component for building custom SVG charts—CustomSVGSeries.
The API is similar to Victory's. You can see I'm using almost the same transformResult
from Victory's snippet.
If you don’t see your favorite library or just want me to add one more—just ping me in this Public Slack Community. I’m happy to add as many libraries as I can to the list.