for (var week = startDate - 14; week < endDate + 14; week += 7) {
scale.push(week * ONE_DAY);
}
- } else { // daily
+ } else if (dateSpan > 1) { // daily
for (var day = startDate - 14; day < endDate + 14; day += 1) {
scale.push(day * ONE_DAY);
}
+ } else { // hourly
+ for (var hour = (startDate - 1) * 24;
+ hour < (endDate + 1) * 24; hour += 1) {
+ scale.push(hour * 60*60*1000);
+ }
}
var xTicks = [];
rollingData[i] = [originalData[i][0], [ 1.0 * mid / count,
1.0 * (mid - low) / count,
1.0 * (high - mid) / count ]];
+ }
} else {
// Calculate the rolling average for the first rollPeriod - 1 points where
// there is not enough data to roll over the full number of days
*/
DateGraph.prototype.dateParser = function(dateStr) {
var dateStrSlashed;
- if (dateStr.search("-") != -1) {
+ if (dateStr.length == 10 && dateStr.search("-") != -1) { // e.g. '2009-07-12'
dateStrSlashed = dateStr.replace("-", "/", "g");
while (dateStrSlashed.search("-") != -1) {
dateStrSlashed = dateStrSlashed.replace("-", "/");
}
- } else if (dateStr.search("/") != -1) {
- return Date.parse(dateStr);
- } else {
+ return Date.parse(dateStrSlashed);
+ } else if (dateStr.length == 8) { // e.g. '20090712'
dateStrSlashed = dateStr.substr(0,4) + "/" + dateStr.substr(4,2)
+ "/" + dateStr.substr(6,2);
+ return Date.parse(dateStrSlashed);
+ } else {
+ // Any format that Date.parse will accept, e.g. "2009/07/12" or
+ // "2009/07/12 12:34:56"
+ return Date.parse(dateStr);
}
- return Date.parse(dateStrSlashed);
};
/**
"20061128,2.97723292469,0.711254751484,2.54237288136,0.648039583782\n" +
"20061129,1.41093474427,0.495309102312,3.02013422819,0.701020603129";
}
+
+function HourlyData() {
+return "" +
+"Date,A,B\n" +
+"2009/07/12 00:00:00,3,4\n" +
+"2009/07/12 01:00:00,5,6\n" +
+"2009/07/12 02:00:00,7,6\n" +
+"2009/07/12 03:00:00,6,5\n" +
+"2009/07/12 04:00:00,4,7\n" +
+"2009/07/12 05:00:00,3,6\n" +
+"2009/07/12 06:00:00,4,6"
+}
--- /dev/null
+<html>
+ <head>
+ <title>noise</title>
+ <!--[if IE]>
+ <script type="text/javascript" src="excanvas.js"></script>
+ <![endif]-->
+ <script type="text/javascript" src="../dygraph-combined.js"></script>
+ <script type="text/javascript" src="../dygraph.js"></script>
+ <script type="text/javascript" src="data.js"></script>
+ </head>
+ <body>
+ <p>Hourly data:</p>
+ <div id="g" style="width:600px; height:300px;"></div>
+
+ <script type="text/javascript">
+ g = new DateGraph(
+ document.getElementById("g"),
+ HourlyData, null, {}
+ );
+ </script>
+ </body>
+</html>