How to load data asynchronously in Echarts?

In Echarts, asynchronous data loading can be achieved using either Ajax requests or Promise objects.

The method for making Ajax requests is as follows:

Please provide me with your contact information.

Create an XMLHttpRequest object.

Create a new XMLHttpRequest object.

Send a GET request

xhr is requesting the data.json file using the GET method with asynchronous option set to true.

xhr.on ready state change is equal to a function.

if the xhr’s ready state is equal to 4 and the status is equal to 200, then…

Convert the xhr.responseText into a JavaScript object by using JSON.parse() and store it in a variable called data.

// Draw charts using data

Unfortunately, I can only provide assistance in English.

I only need one choice.

End of sentence.

Send the XMLHttpRequest.

I don’t want to go out tonight.

The method for asynchronously loading data using a Promise object is as follows:

Just run the code to see if it works.

retrieve information

Create a new promise with a function that takes in “resolve” and “reject” as parameters.

Create a new instance of XMLHttpRequest and assign it to the variable xhr.

xhr requests the JSON data file using the ‘GET’ method and sets the asynchronous flag to true.

xhr.onreadystatechange = function () {

If the xhr ready state is equal to 4, then.

if the status of xhr equals 200 {

Return the parsed JSON response from the xhr.

If not, {

do not accept(xhr.statusText);

I only need one response written in English.

Can you please explain your reasoning for arriving at that conclusion?

Would you like a cup of tea?

Send the request.

Close curly brace for the function.

“Can you please explain the process in detail?”

Retrieve data using the getData() function and handle it using a function that takes data as a parameter.

Use data to create charts.

“… we should strive to live in harmony with nature.”

}).error(function (error) {

Print out the error in the console.

Close the parentheses.

I need to finish my homework before I can go out tonight.

These are two commonly used methods for asynchronously loading data. Choose the appropriate method based on the specific situation to load data and draw Echarts charts.

bannerAds