使用Highcharts.js创建穿孔卡样式图

时间:2012-02-14 14:18:43

标签: javascript highcharts

我想复制github上通过highcharts呈现的“打卡”样式图。

GitHub Punch Card Graph

我真的很挣这个,这是一个jsfiddle开始让我在那里。我宁愿在x和y上有时间,但是我不知道该怎么做才能做到这一点。

任何帮助表示感谢。

TIA!

3 个答案:

答案 0 :(得分:8)

我无法翻转轴,但为你整理了很多东西。

<强> 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}]
}]
});

答案 1 :(得分:5)

我想现在已经很晚了,但也许这个解决方案可以帮助处于相同情况的其他人。

这是我的解决方案:

$(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) }},

      ]
    }]

  });

});

以下是演示:http://jsfiddle.net/KmPJE/1/

请告诉我这是否适合您。

答案 2 :(得分:2)

来自@mangobug的updated the jsFiddle来指导您更接近实现自己想做的事情