Display a "waiting" message until the data is fetched, and subsequently populate the chart with Ajax and Highcharts

I'm currently facing a challenge with my php scripts that fetch data, as they take quite a long time to complete. Consequently, this delays the loading time of highcharts on my website, since the chart is only displayed once the data retrieval process is finished.

This results in the page appearing blank until all the data is retrieved. My goal is to have the highcharts load immediately and show a 'loading' message without any data, and then dynamically update the graph series with the returned data from the php scripts.

Therefore, I'm seeking examples or guidance on how to achieve this functionality. Additionally, I've encountered an issue where I can only set the data within the $(document).ready(function() function.

An example where it works:

But this breaks:

Thank you very much for your assistance and any help provided will be greatly appreciated.

Answer №1

If you're still in need of this information, I can help you with displaying a "loading" message using the "setLoading()" method on the chart.

Let's say you have an instance called pipeline_by_sales_stage_highchart. To display the loading message, you can use the following code: 

pipeline_by_sales_stage_highchart.setLoading("Loading...")

For a practical example, you can check out this demo on JSFiddle: http://jsfiddle.net/QSfEJ/

Answer №2

Modifying a variable outside its scope is not possible, you must either move it into that specific scope or declare it as a global variable.

Answer №3

Check out my response over here: Updating Highchart series in javascript


Summary of the solution:

To begin, initialize the chart with empty series and then update the chart using the addSeries method within a loop:


this.apiData.forEach(function(serie) { // for each row of data, add a series
  this.chart.addSeries(serie, false); // use false to prevent redrawing
}.bind(this));

this.chart.redraw(); // manually redraw the chart
this.chart.hideLoading(); // stop loading if showLoading() was called before

You can also find a working example on jsFiddle: https://jsfiddle.net/qyh81spb/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Continuously retrieving information from a database to display on a web page

Our team is currently developing a solution that requires a dashboard with basic views and charts that need to be updated every 10 seconds when active. Each user will have the same charts but showing filtered information. In order to achieve this function ...

How to Retrieve a Specific Line with jQuery

Could jQuery be used to retrieve the offset of the first letter in the 5th visual line of a block's content? I am referring to the visual line determined by the browser, not the line seen in the source code. ...

Obtaining a return value from a function that involves a series of chained Ajax requests in jQuery

I'm facing an issue with my function that involves chained Ajax requests. Function A and B are both Ajax requests, where A runs first and B runs after A returns its data. The problem arises when Function C executes Function B. Upon execution of Funct ...

Ways to stop a JavaScript function from running during page loading

After clicking the submit button on my form, I want to send a confirmation post using the sendPostAjax() function before submitting the form to the payment provider. However, I'm facing an issue where the sendPostAjax() function is getting executed as ...

When I clicked on the event in Javascript, the result was not what I expected

I am currently working on a web project centered around cooking recipes. In order for users to add ingredients to their recipes, they must input them one by one into a dynamic list that I am attempting to code using jQuery (AJAX). My issue arises when a u ...

Displaying foreign exchange rates using Shield UI Chart

In my quest to access and display forex data, I have stumbled upon the incredible Shield UI Chart. After some experimentation, I successfully mastered the art of implementing ajax: $.ajax({ url: 'http://api.apirates.com/jsonp/update', dataTy ...

Can a form and an HTML request be sent using the same event with Mootools?

$('submitbutton').addEvent( 'submit', function(e){ e.stop(); $('fuss').send(); req2.send(); }); Struggling to make this code work, I'm unsure if it's even possible as my attempts have been unsuccessful so far ...

The Rails text area fails to load through JavaScript when a line break is detected

My comment form has a feature that displays the content of the text area using js. It functions properly unless a new line is entered in the text area, in which case it does not show up right away. However, after refreshing the page, the comment appears wi ...

Access Denied: Phonegap Is Off Limits

I am in the process of developing an Android and iOS application. In order to accomplish this, I need to utilize cross-domain ajax requests since I am using Phonegap for development purposes. The issue I'm facing is as follows: when I access my server ...

Error in PHP script when making an AJAX call

First of all, I want to thank you all for your help. The script is creating a table but sending empty information. I have tried to modify it like this: However, when I call the script, it gives me an error: So, I have edited the script code to clean it ...

Unexpected issue with Typo3 v9 - receiving empty Ajax Plugin JSON response

Consider the following setup in TYPO3 for an ajax request: ajaxAutocomplte_page = PAGE ajaxAutocomplte_page { typeNum = 111871 10 = COA_INT 10 { userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run extensionNa ...

Incorporate Product Choices into Shopping Cart using AJAX and <form> | Opencart

I'm new here and would really appreciate any help with my first question. I've searched for related information, but nothing quite fits what I need. Currently, I'm attempting to add a product along with its options to the cart using an HTML ...

Populate a pair of div elements using just one AJAX request

Currently, I am attempting to use the load() function to ajaxly load two separate divs, #follow-x and #follow-y, by clicking a button. The approach I have taken is as follows within the success function of my code snippet. However, this method does not see ...

Incorporating PayUMoney into MVC and utilizing ajax for seamless integration

Whenever the user clicks on a button, I want them to be redirected to the PayUMoney gateway. If the payment is successful, then the user's data should be stored in the database and they should be redirected to a success page. Otherwise, they should be ...

What is the process for accessing a website using Java programming language?

Currently, I have a jar file up for sale that requires users to sign up on a particular website in order to download it. My issue lies in wanting to verify if purchasers have a valid login for the site when they run the jar file. Despite my attempts with h ...

Ajax undoes any modifications enacted by JavaScript

When using ajax, I trigger an OnTextChangedEvent. Before this event occurs, there is a Javascript function that validates the input field and displays text based on its validity. However, once the Ajax is executed, it resets any changes made by the Javascr ...

Loading jQuery on Ajax can be a challenge

I am currently faced with the challenge of working on code that I did not write myself or fully comprehend. The page utilizes AJAX to dynamically load content, and my goal is to manipulate this content. However, when I try to apply jQuery to the dynamic el ...

Enhance your search experience with AJAX-powered search boxes

I need to implement multiple textboxes on my webpage, each with its own search query to retrieve data from the database. While I have successfully implemented this for one textbox, I am facing difficulties getting it to work for two or more textboxes. He ...

Send the ID through an Html.ActionLink using ajax to retrieve a specific partial view

I am facing an issue with my MVC View page. It is strongly-typed to a list of products, each with a unique id. I have implemented an Html.ActionLink for each product item on the page, and I want to use jQuery's $.ajax function to load a partial view o ...

Using Ajax and jQuery to fetch information from a previous search query

I'm currently utilizing Ajax and jQuery for my chat feature. Some may find it overly complex, but as long as it works, that's all that matters. It's functioning properly on the first friend result, however, not on the others. The issue lies ...