Search code examples
jfreechart

Create GitHub punch card like plots with JFreeChart


I am looking for suggestions as how to create plots similar to GitHub punch cards with JFreeChart. E.g.

enter image description here

I guess it's some variant of a heat map, or two dimensional histogram.


Solution

  • Ok, so I found XYBubbleRenderer which looks like a good starting point.

    • create a MatrixSeries with rows = 7, columns = 24
    • fill in the frequencies accordingly. I found it useful to normalise the values first to 0...1, then take the square root (smaller values have a bit better visible circles), then multiply by 0.5 (otherwise the circles are too large)
    • create a MatrixSeriesCollection from that
    • use ChartFactory.createBubbleChart
    • the circle outline can only be removed via plot.getRenderer.setSeriesOutlinePaint(0, new Color(0, 0, 0, 0))
    • ensure integer tick units on both axis
    • x-axis range -0.5 to 23.5, y-axis range -0.5 to 6.5 (or 0.5 to 7.5 if you use Calendar.DAY_OF_WEEK)
    • custom NumberTickUnit for the y-axis to use day labels instead of numbers

    The result:

    enter image description here