I get some data using Node.js. And I have an HTML file with Google Chart. I want to send the info which I get in Node.js to the Google Chart in my HTML, so that when I open the page I can see the chart with info which I got in Node.js.
I don't have a clue how to do that. I need to show this data in the chart. How can I send this data from a js file to the chart in the HTML file?
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var tableData = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 10],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
var options = {
title: 'My Daily Activities'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(tableData, options);
}
</script>
</head>
<body>
<div id="piechart" style="width: 900px; height: 500px;"></div>
<script src="../app.js"></script>
</body>
</html>
JS
const express = require("express");
const request = require("request");
const https = require("https");
const app = express();
app.get("/", function(req, res){
const url = "https://api.caw.sh/v3/covid-19/countries/ukraine?strict=true";
https.get(url, function(response){
console.log(response.statusCode);
response.on("data", function(data){
const covidData = JSON.parse(data);
console.log(covidData.cases);
})
})
res.send("Success");
})
app.listen(3000, function(){
console.log("Server is tunning on port 3000.");
})