I am using Highcharts to create a waffle chart. Here's a good example:
https://datavizproject.com/data-type/percentage-grid/
Highcharts calls them "item charts", and they work pretty well.
However, I can't figure out how to control the spacing/padding between the items.
I've tried using the itemPadding property, but that only seems to set the padding between the rows, but not the columns.
Here's a working fiddle:
https://jsfiddle.net/stuehler/frt80u2p/4/
As you can see in this screenshot below, the row padding is 1px (itemPadding: 1 - that's what I want), but the column padding is much larger:
Here is the code I'm using:
Highcharts.chart('container', {
chart: {
type: 'item'
},
series: [{
marker: {
symbol: 'square'
},
itemPadding: 1,
rows: 10,
data: [
{
name: 'Male',
y: 43
},
{
name: 'Female',
y: 57
}
]
}]
});
Thanks in advance for your help!


If you are willing to extend/overwrite, here is some food for thought on how to achieve the spacing. Take the examples below as they are. The code is not production ready in terms of maturity or testing.
Example 1
It just sets the
plotWidthsuch that it is equal toplotHeightduring the call todrawPoints, giving each cell the same width and height. It ends up showing correctly for some simple demo scenarios, but the chart is shown aligned to the left.See this JSFiddle demonstration. It should perhaps be using
Math.minfor width and height.Example 2
This is essentially a full overwrite of the
drawPointscode, using the original as a source. It defines thecellWidthandcellHeightvariables differently from the original, making the cells square. It also defines aleftPaddingvariable to be able to center the chart in the plot.See this JSFiddle demonstration.