6

I'd like to replicate the "punch-card" style graph presented on github via highcharts.

GitHub Punch Card Graph

I'm really struggling with this one, here's a jsfiddle that starts to get me there. I'd rather have days on the y and time on the x, but I'm at a loss at to how I should go about doing this.

Any help appreciated.

TIA!

3
  • Updated jsfiddle with a modification of mangobug's suggestion. All that's left is to get time on the y-axis.
    – Bobby B
    Feb 14, 2012 at 15:41
  • 1
    Here's another update that gets the y and x axis labels how you want: jsfiddle.net/CA2cT/8
    – Mark
    Feb 14, 2012 at 22:33
  • Perfect finish! Thanks for dragging that across the line.
    – Bobby B
    Feb 15, 2012 at 15:21

3 Answers 3

8

I was not able to flip the axis but sorted out a lot of things for you.

HTML:

<div id="container" style="height: 400px"></div>

JS:

var chart = new Highcharts.Chart({
chart: {
    renderTo: 'container',
    defaultSeriesType: 'scatter'
},

xAxis: {
    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {

},
plotOptions: {
    scatter: {
        marker: {
            radius: 4,
            states: {
                hover: {
                    enabled: true,
                    lineColor: 'rgb(100,100,100)'
                }
            }
        },
        states: {
            hover: {
                marker: {
                    enabled: false
                }
            }
        }
    }
},
series: [{
    data: [{y: 161}, {y: 167}, {y: 165}, {y: 140}, {y: 172}, {y: 163}, {y: 187}, {y: 107}, {y: 147}, {y: 145}, {y: 112}, {y: 199}]
}]
});
2
  • Super close - much appreciated. If I could figure out how to display hours 00:00 through 24:00 on the y-axis then this would be a winner. I updated the fiddle to display Sun-Sat on x-axis. Thanks for getting me closer.
    – Bobby B
    Feb 14, 2012 at 15:40
  • 3
    I'm glad I was of help, though an up vote would have been really encouraging :P kidding. Would try to look into for further improvement.
    – Zain Khan
    Feb 14, 2012 at 18:10
5

I guess it's to late now but maybe this solution will help other people in the same situation.

Here is my solution:

$(function () {
  $('#container').highcharts({

    chart: {
      defaultSeriesType: 'scatter'
    },

    title: {
      text: 'Punchcard'
    },

    xAxis: {
      type: "datetime",
        dateTimeLabelFormats: {
        hour: '%I %P'  
      },
      tickInterval: 3600000 * 1
    },

    yAxis: {
      categories: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
    },

    series: [{
      data: [

        {y: 0, x: 3600000 * 1,  marker: { radius: Math.floor(Math.random()*11) }}, 
        {y: 0, x: 3600000 * 2,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 3,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 4,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 5,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 6,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 7,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 8,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 9,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 10, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 11, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 12, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 13, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 14, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 15, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 16, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 17, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 18, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 19, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 20, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 21, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 22, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 0, x: 3600000 * 23, marker: { radius: Math.floor(Math.random()*11) }},

        {y: 1, x: 3600000 * 1,  marker: { radius: Math.floor(Math.random()*11) }}, 
        {y: 1, x: 3600000 * 2,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 3,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 4,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 5,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 6,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 7,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 8,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 9,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 10, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 11, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 12, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 13, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 14, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 15, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 16, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 17, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 18, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 19, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 20, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 21, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 22, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 1, x: 3600000 * 23, marker: { radius: Math.floor(Math.random()*11) }},

        {y: 2, x: 3600000 * 1,  marker: { radius: Math.floor(Math.random()*11) }}, 
        {y: 2, x: 3600000 * 2,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 3,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 4,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 5,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 6,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 7,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 8,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 9,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 10, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 11, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 12, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 13, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 14, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 15, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 16, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 17, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 18, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 19, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 20, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 21, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 22, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 2, x: 3600000 * 23, marker: { radius: Math.floor(Math.random()*11) }},

        {y: 3, x: 3600000 * 1,  marker: { radius: Math.floor(Math.random()*11) }}, 
        {y: 3, x: 3600000 * 2,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 3,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 4,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 5,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 6,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 7,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 8,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 9,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 10, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 11, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 12, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 13, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 14, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 15, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 16, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 17, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 18, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 19, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 20, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 21, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 22, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 3, x: 3600000 * 23, marker: { radius: Math.floor(Math.random()*11) }},

        {y: 4, x: 3600000 * 1,  marker: { radius: Math.floor(Math.random()*11) }}, 
        {y: 4, x: 3600000 * 2,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 3,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 4,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 5,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 6,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 7,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 8,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 9,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 10, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 11, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 12, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 13, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 14, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 15, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 16, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 17, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 18, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 19, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 20, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 21, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 22, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 4, x: 3600000 * 23, marker: { radius: Math.floor(Math.random()*11) }},

        {y: 5, x: 3600000 * 1,  marker: { radius: Math.floor(Math.random()*11) }}, 
        {y: 5, x: 3600000 * 2,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 3,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 4,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 5,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 6,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 7,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 8,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 9,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 10, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 11, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 12, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 13, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 14, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 15, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 16, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 17, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 18, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 19, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 20, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 21, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 22, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 5, x: 3600000 * 23, marker: { radius: Math.floor(Math.random()*11) }},

        {y: 6, x: 3600000 * 1,  marker: { radius: Math.floor(Math.random()*11) }}, 
        {y: 6, x: 3600000 * 2,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 3,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 4,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 5,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 6,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 7,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 8,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 9,  marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 10, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 11, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 12, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 13, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 14, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 15, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 16, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 17, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 18, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 19, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 20, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 21, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 22, marker: { radius: Math.floor(Math.random()*11) }},
        {y: 6, x: 3600000 * 23, marker: { radius: Math.floor(Math.random()*11) }},

      ]
    }]

  });

});

And here is the demo: http://jsfiddle.net/KmPJE/1/

Let me know if that works for you.

1
  • No problem! I'm currently working on a better approach using the bubble charts instead of scatter.
    – Diego
    Jul 2, 2013 at 4:10
2

I updated the jsFiddle from @mangobug to guide you to a closer way of doing what you want

1
  • Uncaught ReferenceError: Highcharts is not defined Jul 7, 2017 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.