I want to add a row to an existing line chart. i.e I want my line chart to change dynamically based on user input.
Can anyone guide me or share a link of working examples or can anyone help me to update my code?
The code below takes an input from the user using request.get parameter and parse it into integer value.
The integer value of humidity along with time stamp are displayed as a line chart.
But here the graph is displayed as a single point everytime i give new input. what and where exactly the code need to be updated to get the desired output?
<html>
<head>
<%
String humid= request.getParameter("humid");
int humid_new = Integer.parseInt(humid);
%>
<script type='text/javascript'>
google.charts.load('current', {'packages':['annotationchart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var timeInMs = Date.now();
var data = new google.visualization.DataTable();
data.addColumn('datetime', 'Date');
data.addColumn('number','Humidity');
data.addRows([
[new Date(timeInMs), <%=humid_new%>]
]);
var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div'));
var options = {
displayAnnotations: true
};
chart.draw(data, options);
}
</script>
</head>
<body>
<div id='chart_div' style='width: 900px; height: 500px;'></div>
</body>
</html>