I'm having a problem with javascript code. I am trying to have dynamical chart, which will update on changing a select field with plotly.reshape function. I call an Ajax request based function inside of chart() function and i want it to wait for variable assignment and then draw a chart. I think i'm using async/await in a wrong place. Can u guys help me ? It is my very first js script, but i need it in project.
function chart(){
  var x = Chart();
  var X =x[0];
  var Close=x[1];
  var High=x[2];
  var Low=x[3];
  var Open=x[4];
  console.log(X);
  var trace1 = {
    x: X, 
    close: Close, 
    decreasing: {line: {color: '#7F7F7F'}}, 
    high: High,
    increasing: {line: {color: '#17BECF'}}, 
    line: {color: 'rgba(31,119,180,1)'}, 
    low:  Low, 
    open: Open, 
    type: 'ohlc', 
    xaxis: 'x', 
    yaxis: 'y'
  };
  var data = [trace1];
  var layout = {
    ...
  };
  
  Plotly.newPlot('chart', data, layout);
  
}
 function Chart(){
  var data, date = [], price = [], open=[], Timestamp=[], High=[], Low = [];
  let selectedItem = document.getElementById('currency-selector').value;
  var url = `http://127.0.0.1:8000/${selectedItem}/`; 
  var x = new Array()
  var requestURL = url; //URL of the JSON data
  var request = new XMLHttpRequest({mozSystem: true}); // create http request  
  request.onreadystatechange = async function() {
   if(request.readyState == 4 && request.status == 200) {
      
      data = JSON.parse(request.responseText);
      
      for (var i=0; i<data.length;i++) {
          date.push(data[i].date)
          price.push(data[i].close);
          High.push(data[i].high);
          open.push(data[i].Open);
          Low.push(data[i].low);
          
      }
      
      //chart(date,price,High,Low,open);   
    }
  
  await request.open('GET', requestURL, true);
  request.send(); // send the request
  
}
  return [date,price,High,Low,open];
  }
 
    