DATA STORIES | ANIMATED BAR CHART | KNIME ANALYTICS PLATFORM

Bar Chart Race with KNIME

A codeless solution to enrich your dashboard

bedy kharisma
Low Code for Data Science
4 min readOct 12, 2022

--

Photo by Volodymyr Hryshchenko on Unsplash.

Yes, KNIME has it too.

I have some data and I have been exploring it to see what kind of visualization I could use to tell the story better. Coincidentally, my data is about the rolling stock market, so visualizing a bar chart race will capture nicely the market's dynamics throughout the years. From the dynamics of the rolling stock type ever ordered, which country ordered the most, and which manufacturer got the most? The data can be visualized beautifully using a bar chart race.

The example I have mentioned can be visualized as follows:

For the making of the visualization above, if you are into writing lines of code, Python already has a library to do so. Called bar_chart_race.

Basically, all you have to do is import the library, and set the parameters like the name of dataframe; orientation, either vertical or horizontal, fixed_ max, fixed_order, etc. Try to play with the parameters a bit to get the result that you want, the name of the parameters are quite straightforward, so you won’t get lost in translation. Additionally, two parameters are quite important in determining the length and the speed of the race: the period_length will determine the length of the entire race, from start to finish; and the steps_per_period will determine how long it takes for the bar to be in position for each period.

Note. Make sure that the dataframe has the following format:

So the time stamp, either date or in this case year, is indicated as the dataframe index, while the bar name is indicated as the column’s name. and the value inside the table is the value of each bar in each period of time. So, if your data is not shaped like that, a few tweaks, like data cleaning, filter, sorting, and pivoting might be needed to trim the dataframe.

That’s it if you are into writing lines of codes, of course. If you are not a fan of coding, KNIME has a verified component that allows the same without writing a single line of code.

Introducing the Animated Bar Chart component

A simple drag-and-drop of the Animated Bar Chart verified component from the KNIME Hub is all you need to do to create an animated bar chart or bar chart race. This component only has a few fundamental parameters to configure. It is quite straightforward, and I am sure everyone will be familiar at the first sight.

Note. Verified Components are a set of components that behave like KNIME nodes, including error handling capabilities, which are developed by KNIME and regularly released on the KNIME Hub.

Basically, it requires you to set the title; the column that contains the names of the racing bars; the metric for the bar size; and the timestamp, which in this case is “year”. And that’s it. But make sure that your data is in the following shape:

Make sure that the timestamp is of Date format, the value as double or integer, and the column name as a string. Depending on your source data a few pre-processing might be required to bring the data in the required shape. The overall workflow in KNIME looks like this:

In order to bring the data in the correct shape, a few steps are taken:

  • Pivoting to get the sum value for each type of rolling stock ordered every year.
  • Converting the year, previously as integer, into a date format. This step requires 2 steps, i.e. the conversion of integer into string, and then string into date format.
  • And lastly, we need to unpivot the data table.

Once the pre-processing is completed, we are ready to create our visualization. And voilà, the result can be seen below:

Currently, it is not possible to configure the component to save the animated bar chart as a video or GIF file. They might add such feature in future versions of the component. Therefore, we rely on a different free tool, e.g. ScreenToGif, to capture the animated bar chart, and save it as a GIF file.

So what do you think?

--

--

bedy kharisma
Low Code for Data Science

Indonesian Strategist,Analyst, Researcher, Achievement Addict who helps company grow their business by applying data-driven Management. Follow to follow