It might sound strange, but I have a piece of code here:
let globalResult = [];
let defaultData = ["None", 1200, 1200, 1200, 1200, 1200, 1200, 1200,
1200, 1200, 1200, 1200];
$(document).ready(() => {
// add a listener to the textbox
$('#input').on("change", (evt) => {
let text = $('#input').val();
// sending a parameter named text with the entered value from the textbox
$.get("/display", {text: text})
.done((data) => {
globalResult = data['result'];
$('#input').val(''); // reset the textbox
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
defaultData = globalResult;
}
})
I attempted to swap defaultData
and globalResult
after drawing the Chart, however, it consistently draws a new chart when data is swapped, causing interruptions in the graph rendering. If I move this outside the function drawChart
, it ends up drawing two identical lines with one abruptly ending midway. Placing this outside the $.get()
scope also doesn't work as the chart fails to be drawn. How can I resolve this issue?