score:2
Accepted answer
use onreadystatechange
instead of onload
, don't use request.responsetype = 'json';
and call open()
and send()
after declaring the onreadystatechange
.
var requesturl = 'http://api.holfuy.com/live/?s=101&m=json&tu=c&su=m/s'; //url of the json data
var wdata, hum;
var request = new xmlhttprequest(); // create http request
request.onreadystatechange = function() {
if (request.readystate == 4 && request.status == 200) {
wdata = json.parse(request.responsetext);
hum = wdata.humidity;
console.log(wdata);
console.log(hum);
}
}
request.open('get', requesturl);
request.send(); // send the request
and by the way, you create the hum
variable to store the data you received inside the callback function scope, so the variable hum
does not exist when you are trying to create the chart. create the variable before the ajax request and then populate it inside the callback, that way the variable will have value when you create your chart.
Source: stackoverflow.com
Related Query
- Receiving json data from a server to display a chart.js graph not working
- Not being able to display value from json data into chart js
- Chart not displaying from JSON data
- Data not displaying in Chart JS from PHP JSON
- Live update the charts.js graph on a web page using json data received from a remote server
- How to use 'time' (data from database, data type: timestamp ) for plotting graph in Chart JS
- Chartjs not working with d3 from csv source
- chart js chart bar chart not showing data from 0
- How can I show JSON data in Chart.js with Javascript if static values are working but dynamic from mySQL are not?
- How to display chart using Chartjs with JSON data in Laravel
- Chart.js not updating or receiving data from Flask python
- How do I display chart on my HTML page based on JSON data sent by Node JS
- Populating Chart.Js line graph with multiple lines using data from a JSON Object
- How to get Data from API to display chart using chartjs in Vuejs
- chart js not dispalying data array that comes from an axios request
- JS node chart from SQL Server not updated
- Mapping data from JSON not parsing well
- The chart doesn't display the data from my call to the API with Axios
- Updating chart.js not working after recieved new data from database with ajax
- Vertical align bar chart from chart.js not working
- Chart.js not rendering chart with data from mySQL database
- Angular6 and ng2-charts does not display any charts when i fill data from webservice
- To display data from mock server into chartjs using ember
- get JSON data from function to give value to Chart JS
- Chart JS not working with Dynamic Data
- ionic display chartjs data from json http request
- angular 4 line chart data is not showing data from http get
- How to fetch data from Json file on charts(bar-chart/pie chart etc) in angular?
- Why is the data from my API not displaying on my chart.js chart in React?
- Chart.js 3.x not able to display data on chart
More Query from same tag
- How to remove automatically applied background color to the body?
- chartjs how to change decimal to integers X-axis
- integrate a scroll bar along with chartjs-zoom-plugin
- Chart.Js - Display only specific (fixed) X axis labels
- How to call a typescript arrow function and a javascript function in the same event
- ChartJS: Chart not displaying full range of data
- Draw a horizontal and vertical line on mouse hover in chart js
- How to create chartjs chart with data from database C#
- chartJS or/and php print_r not working together
- ChartJS replay chart animation when called by show()
- Adding labels and colours to Chart.JS from arrays
- how can I show only 2 numbers on the xAxe in Chartjs having more than two numbers on the chart? (line chart)
- chart looking strange on phone´s browser using chart.js
- React-Chartjs-2 and Chartjs v3:Option Property
- dyamically constructing javascript object
- Pie Chart Label is not visible in ReactJS
- Angular chart js how to use formatter with Doughnut chart
- ChartJS for 1 and 0 values display true or false
- ChartJS Label Names Not Showing, Just ID
- How to stop resizing chart.js in case hovered and out of boundaries?
- Chart js - Customize chart
- ChartJS 2.7.0 updating and exporting as png
- How to change React chartjs-2 legend click functionality to hide all except the one clicked?
- Chart.js v2: How to make tooltips always appear on pie chart?
- Grab array from div text to plot with ChartJS
- Chart.js chart does not display when inside an ngIf.
- Cannot rotate label in chart js annotations plugin
- Javascript Chart: How to hide the data
- Append second dataset to existing chartjs chart
- Chart JS date-hour AxesX