stats.js 1.9 KB
$(document)
		.ready(
				function() {
					var options = {
						chart : {
							renderTo : 'hccontainer',
							type : 'spline'
						},
						title : {
							text : 'Snow depth at Vikjafjellet, Norway'
						},
						subtitle : {
							text : 'Irregular time data in Highcharts JS'
						},
						xAxis : {
							type : 'datetime',
						},
						yAxis : [ {
							title : {
								text : 'Snow depth (m)'
							},
							min : 0
						}, {

						} ],
						tooltip : {
							formatter : function() {
								console.log(this.x);
								return '<b>'
										+ this.series.name
										+ '</b><br/>'
										+ Highcharts.dateFormat('%e. %b',
												this.x) + ': ' + this.y + ' m';
							}
						},
						series : [
								{
									name : 'Winter 2007-2008',
									data : [ [ Date.UTC(2012, 9, 27), 0 ],
											[ Date.UTC(2012, 10, 10), 0.6 ],
											[ Date.UTC(2012, 10, 18), 0.7 ],

									]
								}, {
									name : 'asd2',
									data : [ {} ]
								} ]

					};

					$.getJSON(
									'#{request.contextPath}/rest/acc/boughtTimecount/27',
									function(data) {

										console.log(options.series);
										console.log(data);

										var series = data[0].series;
										for (var serIdx = 0; serIdx < series.length; ++serIdx) {
											var d = series[serIdx].data;

											for (var i = 0; i < d.length; i++) {
												if (d[i] instanceof Array) {
													console
															.log("Already array. not traversing");
												} else {
													series[serIdx].data[i] = d[i].item;
												}
											}
										}

										options.series = series;
										console.log(options.series);
										$("#hccontainer").highcharts(options);
									}).done(function() {
								console.log("second success");
							}).fail(function() {
								console.log("error");
							}).always(function() {
								console.log("complete");
							});
				});