var chart; var chartData = []; var chartCursor; function generateChartData() { chartData.push({ datetime:1400035810000, weight:1.62, preAlert:65.00, alert: 75.00 }); chartData.push({ datetime:1402680177000, weight:0.85, preAlert:65.00, alert: 75.00 }); chartData.push({ datetime:1402739065000, weight:1.03, preAlert:65.00, alert: 75.00 }); chartData.push({ datetime:1407363799000, weight:-0.08, preAlert:5.00, alert: 26.38 }); chartData.push({ datetime:1408023780000, weight:-0.25, preAlert:65.00, alert: 75.00 }); chartData.push({ datetime:1408452727000, weight:-0.33, preAlert:65.00, alert: 75.00 });} function showChart() { generateChartData(); // SERIAL CHART chart = new AmCharts.AmSerialChart(); chart.pathToImages = "images/"; chart.zoomOutButton = { backgroundColor: '#000000', backgroundAlpha: 0.15 }; chart.dataProvider = chartData; chart.categoryField = "datetime"; // listen for "dataUpdated" event (fired when chart is rendered) 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.dashLength = 1; categoryAxis.gridAlpha = 0.15; categoryAxis.axisColor = "#DADADA"; // value var valueAxis = new AmCharts.ValueAxis(); valueAxis.axisAlpha = 0.2; valueAxis.dashLength = 1; chart.addValueAxis(valueAxis); // GRAPH var graph1 = new AmCharts.AmGraph(); graph1.title = "Current weight"; graph1.valueField = "weight"; graph1.type = "smoothedLine"; graph1.bullet = "round"; graph1.bulletBorderColor = "#007ACC"; graph1.bulletBorderThickness = 2; graph1.lineThickness = 2; graph1.lineColor = "#007ACC"; graph1.negativeLineColor = "#007ACC"; graph1.hideBulletsCount = 10; // this makes the chart to hide bullets when there are more than 50 series in selection chart.addGraph(graph1); // GRAPH var graph2 = new AmCharts.AmGraph(); graph2.title = "Pre alert"; graph2.valueField = "preAlert"; graph2.bullet = "round"; graph2.bulletBorderColor = "#DE7E18"; graph2.bulletBorderThickness = 1; graph2.lineThickness = 1; graph2.lineColor = "#DE7E18"; graph2.negativeLineColor = "#DE7E18"; graph2.hideBulletsCount = 10; // this makes the chart to hide bullets when there are more than 50 series in selection chart.addGraph(graph2); // GRAPH var graph3 = new AmCharts.AmGraph(); graph3.title = "Alert"; graph3.valueField = "alert"; graph3.bullet = "round"; graph3.bulletBorderColor = "#B0102F"; graph3.bulletBorderThickness = 1; graph3.lineThickness = 1; graph3.lineColor = "#B0102F"; graph3.negativeLineColor = "#B0102F"; graph3.hideBulletsCount = 10; // this makes the chart to hide bullets when there are more than 50 series in selection chart.addGraph(graph3); // CURSOR chartCursor = new AmCharts.ChartCursor(); chartCursor.cursorPosition = "mouse"; chart.addChartCursor(chartCursor); // SCROLLBAR var chartScrollbar = new AmCharts.ChartScrollbar(); chartScrollbar.graph = graph1; chartScrollbar.scrollbarHeight = 40; chartScrollbar.color = "#000000"; chartScrollbar.autoGridCount = true; chart.addChartScrollbar(chartScrollbar); // LEGEND var legend = new AmCharts.AmLegend(); legend.bulletType = "round"; legend.equalWidths = false; legend.valueWidth = 50; legend.color = "#000000"; chart.addLegend(legend); // WRITE chart.write("chartdiv"); }; // this method is called when chart is first inited as we listen for "dataUpdated" event function zoomChart() { // different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues chart.zoomToIndexes(chartData.length - 30, chartData.length - 1); } // changes cursor mode from pan to select function setPanSelect() { if (document.getElementById("rb1").checked) { chartCursor.pan = false; chartCursor.zoomable = true; } else { chartCursor.pan = true; } chart.validateNow(); }