Skip to content

Instantly share code, notes, and snippets.

@cdeckert
Created April 21, 2015 17:52
Show Gist options
  • Save cdeckert/c6dcf7ced594bef858c5 to your computer and use it in GitHub Desktop.
Save cdeckert/c6dcf7ced594bef858c5 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
</head>
<body>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<script type="text/javascript">
$(function () {
var result = {"calcResults":[{"timestamp":1412114400000,"value":36.5},{"timestamp":1412200800000,"value":52.81},{"timestamp":1412373600000,"value":22.188},{"timestamp":1412546400000,"value":61.137},{"timestamp":1412632800000,"value":73.643},{"timestamp":1412719200000,"value":48.095},{"timestamp":1412805600000,"value":52.602},{"timestamp":1412892000000,"value":36.233},{"timestamp":1412978400000,"value":22.087},{"timestamp":1413151200000,"value":48.772},{"timestamp":1413237600000,"value":59.0},{"timestamp":1413324000000,"value":62.085},{"timestamp":1413410400000,"value":59.672},{"timestamp":1413496800000,"value":50.955},{"timestamp":1413583200000,"value":22.25},{"timestamp":1413669600000,"value":20.4},{"timestamp":1413756000000,"value":58.209},{"timestamp":1413842400000,"value":21.974},{"timestamp":1413928800000,"value":20.638},{"timestamp":1414015200000,"value":48.148},{"timestamp":1414101600000,"value":56.972},{"timestamp":1414188000000,"value":22.947},{"timestamp":1414274400000,"value":20.0},{"timestamp":1414364400000,"value":56.115},{"timestamp":1414450800000,"value":55.721},{"timestamp":1414537200000,"value":43.994},{"timestamp":1414623600000,"value":55.453},{"timestamp":1414710000000,"value":57.206},{"timestamp":1414969200000,"value":56.974},{"timestamp":1415055600000,"value":56.865},{"timestamp":1415142000000,"value":29.491},{"timestamp":1415228400000,"value":34.755},{"timestamp":1415314800000,"value":65.875},{"timestamp":1415401200000,"value":22.038},{"timestamp":1415574000000,"value":60.385},{"timestamp":1415660400000,"value":65.965},{"timestamp":1415746800000,"value":57.353},{"timestamp":1415833200000,"value":62.138},{"timestamp":1415919600000,"value":60.469},{"timestamp":1416006000000,"value":22.227},{"timestamp":1416092400000,"value":40.5},{"timestamp":1416178800000,"value":51.556},{"timestamp":1416265200000,"value":59.966},{"timestamp":1416351600000,"value":52.156},{"timestamp":1416438000000,"value":61.201},{"timestamp":1416524400000,"value":53.311},{"timestamp":1416610800000,"value":21.846},{"timestamp":1416783600000,"value":21.971},{"timestamp":1416870000000,"value":21.061},{"timestamp":1416956400000,"value":63.074},{"timestamp":1417042800000,"value":59.538},{"timestamp":1417129200000,"value":49.851},{"timestamp":1417215600000,"value":27.333},{"timestamp":1417388400000,"value":78.2},{"timestamp":1417561200000,"value":62.0},{"timestamp":1417647600000,"value":60.875},{"timestamp":1417734000000,"value":59.5},{"timestamp":1417820400000,"value":30.0},{"timestamp":1417993200000,"value":46.5},{"timestamp":1418079600000,"value":54.0},{"timestamp":1418166000000,"value":64.733},{"timestamp":1418252400000,"value":65.125},{"timestamp":1418338800000,"value":54.571},{"timestamp":1418425200000,"value":21.5},{"timestamp":1418598000000,"value":47.4},{"timestamp":1418684400000,"value":35.0},{"timestamp":1418770800000,"value":20.5},{"timestamp":1418857200000,"value":62.722},{"timestamp":1418943600000,"value":57.0},{"timestamp":1419030000000,"value":21.0},{"timestamp":1419202800000,"value":65.8},{"timestamp":1419289200000,"value":69.0},{"timestamp":1419807600000,"value":32.75},{"timestamp":1419894000000,"value":36.364}],"regResults":[[{"timestamp":1412114400000,"value":46.986},{"timestamp":1412978400000,"value":43.398}],[{"timestamp":1412978400000,"value":28.241},{"timestamp":1413410400000,"value":67.673}],[{"timestamp":1413410400000,"value":38.613},{"timestamp":1416092400000,"value":51.736}],[{"timestamp":1416092400000,"value":47.031},{"timestamp":1416524400000,"value":59.199}],[{"timestamp":1416524400000,"value":37.623},{"timestamp":1417993200000,"value":56.595}],[{"timestamp":1417993200000,"value":47.598},{"timestamp":1418252400000,"value":67.581}],[{"timestamp":1418252400000,"value":47.459},{"timestamp":1419894000000,"value":42.199}]],"sectionResults":[{"type":"FALL","fromDate":1412114400000,"toDate":1412978400000,"count":9},{"type":"RISE","fromDate":1412978400000,"toDate":1413410400000,"count":4},{"type":"RISE","fromDate":1413410400000,"toDate":1416092400000,"count":28},{"type":"RISE","fromDate":1416092400000,"toDate":1416524400000,"count":5},{"type":"RISE","fromDate":1416524400000,"toDate":1417993200000,"count":13},{"type":"RISE","fromDate":1417993200000,"toDate":1418252400000,"count":3},{"type":"FALL","fromDate":1418252400000,"toDate":1419894000000,"count":12}],"thresPredRiseResult":{"remainingTime":-1610446553,"value":50.0},"thresPredFallResult":{"remainingTime":-2434663081,"value":50.0}}
getData = function(data)
{
var dataResult = [];
for (var i = 0; i < data.length; i++) {
record = data[i];
dataResult.push([record["timestamp"], record["value"]]);
};
console.log(dataResult);
return dataResult;
}
getRegression = function(data)
{
var dataResult = [];
for(var i = 0; i< data.length; i++)
{
for(var j = 0; j < data[i].length; j++)
{
record = data[i][j];
dataResult.push([record["timestamp"], record["value"]]);
}
// push NULL
// dataResult.push(null)
}
return dataResult;
}
$('#container').highcharts({
chart: {
type: 'spline',
zoomType: "x"
},
title: {
text: 'Snow depth at Vikjafjellet, Norway'
},
subtitle: {
text: 'Irregular time data in Highcharts JS'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { // don't display the dummy year
month: '%e. %b',
year: '%b'
},
title: {
text: 'Date'
}
},
yAxis: {
title: {
text: 'Snow depth (m)'
}
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x:%e. %b}: {point.y:.2f} m'
},
plotOptions: {
spline: {
marker: {
enabled: true
}
}
},
series: [{
name: 'act mot Temp',
data: getData(result["calcResults"])
},
{
name: 'Regression',
data: getRegression(result["regResults"])
}
]
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment