// declaring variables var chart; var dataProvider; // this method called after all page contents are loaded window.onload = function() { } // method which loads external data function loadCSV(file) { if (window.XMLHttpRequest) { // IE7+, Firefox, Chrome, Opera, Safari var request = new XMLHttpRequest(); } else { // code for IE6, IE5 var request = new ActiveXObject('Microsoft.XMLHTTP'); } // load request.open('GET', file, false); request.send(); parseCSV(request.responseText); } function convertAtoH(hexstring,size){ hexstring = hexstring.substring(0,size); return parseInt(hexstring,16); } // ---------------------------------------------------------- Parser // method which parses csv data function parseCSV(data){ var i,t1,t2,t3,t4,t5,t6,t7,value,i,a1,a2,a3,a4,timestamp; var STRL; dataProvider = []; var string = data; STRL=data.length; // set data provider to the chart // chart.dataProvider = dataProvider; // ------------------------------------------------------------------------------------------------------------------- for (i=0;i < STRL;i) { var size = convertAtoH(string,2); string = string.substring(2); // ---------------------------------------------------------- Timestamp lesen timestamp=convertAtoH(string,2); string = string.substring(2); timestamp+=256*(convertAtoH(string,2)); string = string.substring(2); timestamp+=65536*(convertAtoH(string,2)); string = string.substring(2); timestamp+=16777216*(convertAtoH(string,2)); string = string.substring(2); var date = new Date(); date.setYear(Clock_GetYear(timestamp)); date.setMonth(Clock_GetMonth(timestamp)); date.setDate(Clock_GetDay(timestamp)); date.setHours(Clock_GetHour(timestamp)); date.setMinutes(Clock_GetMinute(timestamp)); date.setSeconds(Clock_GetSecond(timestamp)); // ---------------------------------------------------------- Temperaturen lesen value = convertAtoH(string,4); if(value > 32768) t1 = ((value-65536)/10).toFixed(1); else t1 = (value/10).toFixed(1); string = string.substring(4); value = convertAtoH(string,4); if(value > 32768) t2 = ((value-65536)/10).toFixed(1); else t2 = (value/10).toFixed(1); string = string.substring(4); value = convertAtoH(string,4); if(value > 32768) t3 = ((value-65536)/10).toFixed(1); else t3 = (value/10).toFixed(1); string = string.substring(4); value = convertAtoH(string,4); if(value > 32768) t4 = ((value-65536)/10).toFixed(1); else t4 = (value/10).toFixed(1); string = string.substring(4); value = convertAtoH(string,4); if(value > 32768) t5 = ((value-65536)/10).toFixed(1); else t5 = (value/10).toFixed(1); string = string.substring(4); value = convertAtoH(string,4); if(value > 32768) t6 = ((value-65536)/10).toFixed(1); else t6 = (value/10).toFixed(1); string = string.substring(4); value = convertAtoH(string,4); if(value > 32768) t7 = ((value-65536)/10).toFixed(1); else t7 = (value/10).toFixed(1); string = string.substring(4); string = string.substring(16); value = convertAtoH(string,4); a1 = (value/2); string = string.substring(4); value = convertAtoH(string,4); a2 = (value/2); string = string.substring(4); value = convertAtoH(string,4); a3 = (value/2); string = string.substring(4); value = convertAtoH(string,4); a4 = (value/2); string = string.substring(4); string = string.substring(52); //var dataObject = {date:date, t1:t1, t2:t2, t3:t3, t4:t4, t5:t5, t6:t6, t7:t8, t8:t8, t9:t9, t10:t10}; chartData.push({date:date, t1:t1, t2:t2, t3:t3, t4:t4, t5:t5, t6:t6, t7:t7, a1:a1, a2:a2, a3:a3, a4:a4}); //dataProvider.push(dataObject); i+=(2*size); } // this will force chart to rebuild using new data //chart.validateData(); } // ------------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------- Timestamp - Funktionen function Clock_GetDayAll(stamp) { var help_stamp = 0; var help_year = 2010; var help_year_2 = 2012; for (var i = Clock_GetYear(stamp) - 2010; i > 0; i--) { if (help_year == help_year_2) { help_year_2 += 4; help_stamp += 31622400; } else { help_stamp += 31536000; } help_year++; } stamp -= help_stamp; stamp /= 86400; stamp++; return stamp; } function Is_Leap_Year(_Year) { if ((((_Year % 4) == 0 && (_Year % 100) != 0) || (_Year % 400) == 0)) { return 1; } return 0; } function Clock_GetDay(stamp) { var Clock_Months; var day = Clock_GetDayAll (stamp); var helpday = 0; Clock_Months= [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; for (var help = 0; help < 12; help++) { helpday += help != 1 ? Clock_Months[help] : Clock_Months[help] + Is_Leap_Year(Clock_GetYear(stamp)); if (helpday >= day) { helpday -= help != 1 ? Clock_Months[help] : Clock_Months[help] + Is_Leap_Year(Clock_GetYear(stamp)); break; } } return (day - helpday); } function Clock_GetMonth (stamp) { var Clock_Months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; var help_month = 0; var help_day = 0; var help_day_2 = 0; help_day = Clock_GetDayAll(stamp); for (help_month = 0; help_month < 12; help_month++) { help_day_2 += help_month != 1 ? Clock_Months[help_month] : Clock_Months[help_month] + Is_Leap_Year(Clock_GetYear(stamp)); if (help_day_2 >= help_day) { break; } } return (help_month); } function Clock_GetYear(stamp) { var leap_year = 0; var help_year = 2010; var help_year_2 = 2012; var i; for(i=0;i<1;i) { if (help_year == help_year_2) { help_year_2 += 4; leap_year += 31622400; } else { leap_year += 31536000; } help_year++; if(stamp < leap_year) break; } // while (stamp >= leap_year); return (help_year-1); } function Clock_GetHour(stamp) { return (((stamp - (((stamp - (stamp % 60)) % 3600) + (stamp % 60))) % 86400) / 3600); } function Clock_GetMinute(stamp) { return (((stamp - (stamp % 60)) % 3600) / 60); } function Clock_GetSecond(stamp) { return (stamp % 60); } var chart; var chartData = []; AmCharts.ready(function () { loadCSV("logging.txt"); // SERIAL CHART chart = new AmCharts.AmSerialChart(); chart.pathToImages = ""; chart.dataProvider = chartData; chart.categoryField = "date"; // listen for "dataUpdated" event (fired when chart is inited) and call zoomChart method when it happens chart.addListener("dataUpdated", zoomChart); // AXES // category var categoryAxis = chart.categoryAxis; categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true categoryAxis.minPeriod = "DD"; // our data is daily, so we set minPeriod to DD categoryAxis.minorGridEnabled = true; categoryAxis.axisColor = "#DADADA"; categoryAxis.twoLineMode = true; categoryAxis.dateFormats = [{ period: 'fff', format: 'JJ:NN:SS' }, { // period: 'ss', // format: 'JJ:NN:SS' }, { period: 'mm', format: 'JJ:NN' }, { period: 'hh', format: 'JJ:NN' }, { period: 'DD', format: 'DD' }, { period: 'WW', format: 'DD' }, { period: 'MM', format: 'MMM' }, { period: 'YYYY', format: 'YYYY' }]; // first value axis (on the left) var categoryAxis = chart.categoryAxis; categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true categoryAxis.minPeriod = "mm"; // our data is daily, so we set minPeriod to DD categoryAxis.dashLength = 2; categoryAxis.gridAlpha = 0.15; var tempAxis = new AmCharts.ValueAxis(); tempAxis.axisThickness = 2; tempAxis.gridAlpha = 0; tempAxis.minimum = -40; tempAxis.maximum = 140; tempAxis.unit = "°C"; chart.addValueAxis(tempAxis); var outAxis = new AmCharts.ValueAxis(); outAxis.axisThickness = 2; outAxis.gridAlpha = 0; outAxis.minimum = -500; outAxis.maximum = 1600; outAxis.labelsEnabled = false; outAxis.position = "right"; chart.addValueAxis(outAxis); var outAxis1 = new AmCharts.ValueAxis(); outAxis1.axisThickness = 2; outAxis1.gridAlpha = 0; outAxis1.minimum = -400; outAxis1.maximum = 1700; outAxis1.labelsEnabled = false; outAxis1.position = "right"; chart.addValueAxis(outAxis1); var outAxis2 = new AmCharts.ValueAxis(); outAxis2.axisThickness = 2; outAxis2.gridAlpha = 0; outAxis2.minimum = -200; outAxis2.maximum = 1800; outAxis2.labelsEnabled = false; outAxis2.position = "right"; chart.addValueAxis(outAxis2); var outAxis3 = new AmCharts.ValueAxis(); outAxis3.axisThickness = 2; outAxis3.gridAlpha = 0; outAxis3.minimum = 0; outAxis3.maximum = 1900; outAxis3.labelsEnabled = false; outAxis3.position = "right"; chart.addValueAxis(outAxis3); var guide = new AmCharts.Guide(); guide.value = 0; guide.label = "R1 off"; outAxis.addGuide(guide); var guide = new AmCharts.Guide(); guide.value = 100; guide.label = "R1 on"; outAxis.addGuide(guide); var guide = new AmCharts.Guide(); guide.value = 0; guide.label = "R2 off"; outAxis1.addGuide(guide); var guide = new AmCharts.Guide(); guide.value = 100; guide.label = "R2 on"; outAxis1.addGuide(guide); var guide = new AmCharts.Guide(); guide.value = 0; guide.label = "R3 off"; outAxis2.addGuide(guide); var guide = new AmCharts.Guide(); guide.value = 100; guide.label = "R3 on"; outAxis2.addGuide(guide); var guide = new AmCharts.Guide(); guide.value = 0; guide.label = "R0 off"; outAxis3.addGuide(guide); var guide = new AmCharts.Guide(); guide.value = 100; guide.label = "R0 on"; outAxis3.addGuide(guide); // chart must have a graph var graph = new AmCharts.AmGraph(); graph.valueAxis = tempAxis; graph.title = "S1"; graph.valueField = "t1"; graph.lineColor = "#FF0000"; chart.addGraph(graph); var graph = new AmCharts.AmGraph(); graph.valueAxis = tempAxis; graph.title = "S2"; graph.valueField = "t2"; graph.lineColor = "#009900"; chart.addGraph(graph); var graph = new AmCharts.AmGraph(); graph.valueAxis = tempAxis; graph.title = "S3"; graph.valueField = "t3"; chart.addGraph(graph); var graph = new AmCharts.AmGraph(); graph.valueAxis = tempAxis; graph.title = "S4"; graph.valueField = "t4"; chart.addGraph(graph); var graph = new AmCharts.AmGraph(); graph.valueAxis = tempAxis; graph.title = "S5"; graph.valueField = "t5"; graph.lineColor = "#808000"; chart.addGraph(graph); var graph = new AmCharts.AmGraph(); graph.valueAxis = tempAxis; graph.title = "S6"; graph.valueField = "t6"; // graph.hidden = true; chart.addGraph(graph); var graph = new AmCharts.AmGraph(); graph.valueAxis = tempAxis; graph.title = "S7"; graph.valueField = "t7"; graph.lineColor = "#FFFF00"; // graph.hidden = true; chart.addGraph(graph); var graph = new AmCharts.AmGraph(); graph.valueAxis = outAxis; graph.title = "R1"; graph.valueField = "a1"; graph.lineColor = "#990000"; chart.addGraph(graph); var graph = new AmCharts.AmGraph(); graph.valueAxis = outAxis1; graph.title = "R2"; graph.valueField = "a2"; chart.addGraph(graph); var graph = new AmCharts.AmGraph(); graph.valueAxis = outAxis2; graph.title = "R3"; graph.valueField = "a3"; graph.lineColor = "#000000"; // graph.hidden = true; chart.addGraph(graph); var graph = new AmCharts.AmGraph(); graph.valueAxis = outAxis3; graph.title = "R0"; graph.valueField = "a4"; // graph.hidden = true; chart.addGraph(graph); // CURSOR var chartCursor = new AmCharts.ChartCursor(); chartCursor.categoryBalloonDateFormat = "JJ:NN, DD MMMM"; chartCursor.cursorAlpha = 0.1; chartCursor.fullWidth = true; chart.addChartCursor(chartCursor); // SCROLLBAR var chartScrollbar = new AmCharts.ChartScrollbar(); // chartScrollbar.graph = graph; chartScrollbar.scrollbarHeight = 40; chartScrollbar.color = "#222222"; chartScrollbar.autoGridCount = true; chart.addChartScrollbar(chartScrollbar); // LEGEND var legend = new AmCharts.AmLegend(); legend.marginLeft = 110; legend.markerType = "bubble"; legend.markerSize = 15; legend.switchType = "v"; legend.valueWidth = 30; chart.addLegend(legend); // WRITE chart.write("chartdiv"); }); function zoomChart() { // different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues chart.zoomToIndexes(chartData.length - 1450, chartData.length - 1); }