Bar chart averages are slightly wrong, adding lots of decimal places to labels

If I create a bar chart (with the JavaScript Bar Chart node) that averages several identical values, even if they are integers, some of the resulting values end up being infinitesimally more or less than the original values. For example, if I plot a category consisting of five 3s (that is, an integer column with five rows of the value ‘3’), then hover my cursor over the relevant bar, the label says 'Value: 3.00000000004" (or something close – I didn’t count the exact number of zeros!).

Funnily enough, the value reverts to an exact integer if I only include four rows of 3. And five rows of 2, 4 or 5 also yield proper integers. But five 6s convert to 6.0000000000001.

I assume that this behaviour stems from some quirk of the floating point engine that underlies all the arithmetic in KNIME. Indeed, I can see that the same values are created by the GroupBy node if you view the results with full precision. In most instances, this doesn’t matter. But the bar chart provides no way to correct for these deviations, for example by rounding to a given number of decimals. It is very annoying when some of your data labels show the expected number of decimal places while others show about 12 decimal places, most of them 0s.

Is there some way to fix this, or is there a fix on the horizon?

Hello @AngusVeitch1,

you just have to add a “Math Formula” node between the output table and the bar chart node to use round(x,y) or round(x) formula.


Hi @SamirAbida,

Unfortunately that approach won’t help in this case, because the averaging is done by the Bar Chart node itself. If I could average and round the values first, I would; but the dashboard I am building demands that the input table has multiple rows for the same category. (The reason is that selection events on the bar chart need to trigger the filtering of a table view.) Even if the values going into the bar chart node are integers, the node turns them into imprecise doubles when it averages the values.

I suspect that the only way to fix this would be to have the Bar Chart node to enforce its own rounding after it averages the values.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.