Maybe sounds stupid but the first column of my csv is not the date field.
I can manually edit CSV to change columns order and then works like a charm but since the file is automacally generated I cannot do it frequentely.
Is there any way to set date column if not first?
Edit: here you have sample of my csv
Test server;Date/Time;Latency (ms);Dowload Speed (Kb/s);Upload Speed (Kb/s)
TVAlmansa S.L. (Almansa) [50.87 km];2015/07/07 11:00:31;67.94;57975;25226
Grupo TVHoradada (Pilar De La Horadada) [87.32 km];2015/07/07 12:00:32;46.11;58484;25433
Grupo TVHoradada (Pilar De La Horadada) [87.32 km];2015/07/07 13:00:31;43.75;55262;24106
TVAlmansa S.L. (Almansa) [50.87 km];2015/07/07 14:00:39;89.39;55266;12722
TVAlmansa S.L. (Almansa) [50.87 km];2015/07/07 15:00:35;69.24;56732;22550
1st step to solution
As @danvk says, it seems that dygraphs takes first column from csv file as date argument. There is no way to change this, I just can to load csv file in an array and then set columns I want to display.
Solution
Finally I've used some code based on this post to load and parse my csv file. This is the complete code
//AJAX query for CSV file
var req = new XMLHttpRequest();
req.onreadystatechange = function () {
if (req.readyState == 4) {
if (req.status === 200 || // Normal http
req.status === 0) { // Chrome w/ --allow-file-access-from-files
var data = req.responseText;
drawGraph(data);
}
}
};
req.open('GET', 'bandwith_report.csv', true);
req.send(null);
//Graph draw function
var drawGraph = function(data) {
//data threatment (select columns)
var parsed_data = toArray(data);
var firstRow = parsed_data[0];
var data = parsed_data.slice(1); // Remove first element (labels)
//data display
graph = new Dygraph(
"graphdiv2", //div
data,
{
labels: firstRow
}
);
}
var toArray = function(data) {
//load lines
var lines = data.split("\n");
var arry = [];
//parse lines
for (var idx = 0; idx < lines.length; idx++) {
var line = lines[idx];
// Oftentimes there's a blank line at the end. Ignore it.
if (line.length == 0) {
continue;
}
var row = line.split(";");
// Special processing
// remove first field (including header)
row.splice(0,1);
// parse data (except header)
if (idx > 0) {
row[0] = new Date(row[0]); // Turn the string date into a Date.
// turn string into float
for (var rowIdx = 1; rowIdx < row.length; rowIdx++) {
// Turn "123" into 123.
row[rowIdx] = parseFloat(row[rowIdx]);
}
}
arry.push(row);
}
return arry;
}
No. dygraphs assumes that the first column is the independent (x) axis. If it's not, then you need to modify your data to make it so. Instead of doing this manually, you could do it in JavaScript.