Question

I have an CSV file:

2011-01-11, 0:00, 4  
2011-01-11, 0:05, 2  
2011-01-11, 0:10, 6  
2011-01-11, 0:15, 8  
...  
2011-01-12, 0:00, 4  
2011-01-12, 0:05, 2  
...  
2011-01-13, 20:00, 4  
2011-01-13, 20:05, 2  
...  

What would be the best practice to show only last 48 hour data?

Here is the CSV parser:

$.get('data.csv', function(data) {
                // Split the lines
                var lines = data.split('\n');
                $.each(lines, function(lineNo, line) {
                    var items = line.split(',');

                // header line containes categories
                if (lineNo == 0) {
                    $.each(items, function(itemNo, item) {
                        if (itemNo > 0) options.xAxis.categories.push(item);
                    });
                }

                // the rest of the lines contain data with their name in the first position
                else {
                    var series = { 
                        data: []
                    };
                    $.each(items, function(itemNo, item) {
                        if (itemNo == 0) {
                            series.name = item;
                        } else {
                            series.data.push(parseFloat(item));
                        }
                    });

                    options.series.push(series);

                }

            });

Is it a good way to modify this parser to load only last 288 line (24 hour data) from the CSV? If yes, how I can do that?

Was it helpful?

Solution

Your source is a bit jumbled, but it looks like you could just slice off the lines you want:

var lines = data.split('\n').slice(-288);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top