"Enhance your data visualization with Highcharts Windbarb and effortless AJAX data

Alright. Let's rephrase a question that hasn't been answered yet.

I've got a chart below with data loading dynamically via ajax. A simplified version (without ajax) of this graph works well as shown in this jsfiddle.

The code below represents the chart as I use it, directly from its context.

https://i.sstatic.net/oYB3K.png

The concept involves multiple time series (x-axis) on the graph and I want to display wind characteristics of speed and direction at those times using windbarbs. The windbarbs have two arguments at each defined x-value while all other series have just one argument (y-axis).

  1. My query is: why does it not work (resulting in a stackdump) whereas it works on jsfiddle (minus the ajax call and addSeries call?

  2. A related question: in the jsfiddle the onSeries attribute doesn't function properly. What might be the issue there?

  3. Lastly: is it feasible to have the windbarbs above the series plots rather than fixed on the x-axis?

The problem seems to lie in the loading of the wind data after the other series are loaded. Since that part is within the ajax call with the (idx == 'wind') condition, it's quite easy to identify. It breaks during the setData call of highStock leading to the following stackdump:

Uncaught TypeError: r is undefined
setData highstock.src.js:33902
init highstock.src.js:33182
init highstock.src.js:54816
init windbarb.src.js:361
initSeries highstock.src.js:27886
addSeries highstock.src.js:36888
fireEvent highstock.src.js:2112
addSeries highstock.src.js:36887
success line 2 > injectedScript:176
success line 2 > injectedScript:171
jQuery 6
doSensorIn2p5 line 2 > injectedScript:162
SetGraphView0 line 2 > injectedScript:276
onclick (index):1

Everything runs fine if the wind data is omitted.

var doSensorIn10 = function(){
  let ReferenceColours = ['#79bc6a', '#bbcf4c', '#eec20b', '#f29305', '#960018' ];
  let ReferenceConcentrations10 = [0,25,50,90,180];
  let t ={chart: { renderTo: 'chartcontainerIn10',type: 'spline',alignTicks: false, zoomType: 'xy', pinchType: 'xy'},
  title: { text: 'AirQuality Sensor In for PM10'},
  credits: { enabled: true},
  xAxis: { type: 'datetime', ordinal: false, dateTimeLabelFormats: { day: '%e %b',week: '%e %b %y',month: '%b %y',year: '%Y'} },
  yAxis:
    [{
      title: { text: 'Luchtkwaliteit (μg/m3)'},
      opposite: false, labels: { align: 'right',x: -5},
    },
    {
      linkedTo: 0,
      gridLineWidth: 0,
      opposite: true,
      title: { text: null},
      labels: { align: 'left',x: 5},
      tickInterval: 20
    }],
  legend: { enabled: true},
  tooltip: { valueSuffix: 'μg/m3',valueDecimals: 1,xDateFormat: '%A, %b %e, %H:%M'},
  series:[],
  rangeSelector:
  {
    buttons:[{ count: 6,type: 'hour',text: '6h'},
             { count: 12,type: 'hour',text: '12h'},
             { type: 'all',text: 'All'}],
    inputEnabled: false
  }
};
let chart = new Highcharts.StockChart(t);
chart.showLoading();

$.ajax({
  url: 'airlinkdataIn10.json', 
  cache: false,
  dataType: 'json',
  success: function(resp){
    let titles = {
'In_pm10': 'In_pm10','In_pm10_1hr': 'In_pm10_1hr','In_pm10_3hr': 'In_pm10_3hr','In_pm10_24hr': 'In_pm10_24hr','In_pm10_nowcast': 'In_pm10_nowcast','wind': 'wind'}
    let idxs = ['In_pm10','In_pm10_1hr','In_pm10_3hr','In_pm10_24hr','In_pm10_nowcast','wind']
    let cnt = 0;
    idxs.forEach(function(idx) {
      console.log('idx =  ' + idx);
      if (idx in resp) {
        if (idx == 'wind') {
          console.log('Doing Wind correctly : Before addSeries');
          chart.addSeries({name: titles[idx], type: 'windbarb', showInLegend: false, onSeries: 'InPM2p5', tooltip: {valueSuffix: ' m/s'}, data: resp[idx] }, false);
          console.log('Doing Wind correctly : After addSeries');
        }
        else {
          console.log('Doing ' + idx + ' correctly');
          chart.addSeries({name: titles[idx], data: resp[idx]}, false);
        }
        chart.series[cnt].options.zIndex = cnt+50;
      }
      cnt++;
    });
    chart.hideLoading();
    chart.redraw();
  }
}
)};

The data series (in abbreviated form) looks like this:

{"In_pm2p5":[[1609484460000,26.20], ... ]],
 "In_pm2p5_1hr":[[1609484460000,32.90], ... ]],
 ...
 "wind":[[1609484460000,0.0,194], ...]]}

Each parameter has 2880 values, wind may have one less value (which was tested in jsfiddle without issues).

Answer №1

Thank you for providing such a detailed and clear explanation!

  1. It seems like the issue with the chart not rendering correctly may be related to data fetching. The addSeries function should work smoothly with the windbarb type series.

Demo: https://jsfiddle.net/BlackLabel/ktLyunw8/

2.

In the provided jsfiddle, it appears that the onSeries attribute is not functioning as expected. Can you identify the problem?

Upon inspection, everything seems to be working properly: https://i.sstatic.net/d2Iu7.png

3.

Lastly, is there a way to position the windbarbs above the series graphs instead of being fixed on the x-axis?

Similar to utilizing the onSeries feature? Or possibly displaying them entirely above the plot area?


I would prefer to have the windbarbs displayed above the plot area or at the top of the plot area (as opposed to being at the bottom without onSeries), all aligned in one line.

In this scenario, you can create a second xAxis and allocate the winbarb series to it.

API: https://api.highcharts.com/highcharts/xAxis.opposite

Demo: https://jsfiddle.net/BlackLabel/ud0kyrgh/

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

Looking for a method to incorporate an onclick function into a column for renderCell within the MUI Datagrid. Any suggestions?

I'm currently developing a react application and utilizing the MUI Datagrid to present some data. I have incorporated a rendercell to insert an edit icon which should trigger a pop-up modal when clicked. Below is the column setup. export const specifi ...

Saving JavaScript variables to a JSON file

In my possession is a JSON file named example_json.json, which contains the following data: { "timeline": { "headline":"WELCOME", "type":"default", "text":"People say stuff", "startDate":"10/4/2011 15:02:00", ...

Using a variable as a URL parameter in a jQuery ajax request: tips and tricks

$.ajax({ type:"POST", url:"hostname/projfolder/webservice.php?callback=statusReturn&content="+str_table, contentType: "application/json; charset=utf-8", crossDomain:true, dataType:'jsonp', succe ...

Mesh in threejs does not include the customDepthMaterial property when outputting to scene.toJSON

I have been working on creating an object with the following code: const geometry = new THREE.SphereBufferGeometry(2,100,100); const material = new THREE.MeshPhongMaterial({ map: myImage, transparent: true, side: THREE.DoubleSide, opacity: ...

Passing values from Vue3 child component to parent component

Hey there, I'm currently diving into the world of Vue and I'm working on a table that dynamically displays abbreviations. I've been trying to send a searchTerm from my child component to the parent component, but I'm struggling with ge ...

Is it possible to use next.js to statically render dynamic pages without the data being available during the build process?

In the latest documentation for next.js, it states that dynamic routes can be managed by offering the route data to getStaticProps and getStaticPaths. Is there a way I can create dynamic routes without having to use getStaticProps() and getStaticPaths(), ...

What is the correct way to send an HTTP error code to an error handling middleware?

Currently, I am in the process of developing a RESTful API using node.js and express framework. I would like to create a single error handling middleware for this project. The approach I am currently considering involves: router.get('/some-resource&a ...

Issue: Module 'xml2json' not found

Encountered an error while running my project package. When I tried to install the necessary packages using npm install xml2json I still encountered another error below. Can anyone provide suggestions or ideas on how to resolve this issue? D:\xa ...

What is the method for implementing an 'AND' condition in Firebase or its equivalent?

I have a query requirement where I am looking to display only specific data by using an 'AND' statement or its equivalent. To better explain, I am referencing the example given in the Firebase Documentation. // Find all dinosaurs whose height is ...

AngularJS not displaying loader during AJAX request

While utilizing ajax requests with $http, there seems to be a delay due to the server operation taking longer than expected. I have implemented a loader to display while processing the request, but unfortunately it is not showing up on the page. Even after ...

Struggling with this mixed content problem

Encountering a problem while loading a js file: https://code.jquery.com/jquery-1.11.1.min.js, which is being loaded on my webpage in this manner: <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script> Upon loading my webpage, an ...

cheerio scraping results in an array that is devoid of any data

Struggling to extract data from a website with the URL https://buff.163.com/market/csgo#tab=buying&page_num=1 using request-promise and cheerio. Check out my code snippet below: const request = require('request-promise'); const cheerio = requ ...

Verify whether the cookie information is in an array format

As visitors click on products on my site, I am storing their IDs in a cookie. Each click adds the new ID to an array stored in the cookie. This is how I set up the cookie and its current value after a few clicks: var cookieArray = []; cookieArray.push( ...

My goal is to have the "show more" button reveal extra information without having to reload the entire page

I’m trying to figure out how to make the “more” button show additional information without reloading the entire page. I’ve done some research online and found that AJAX can help with this, but since I’m just starting to learn JavaScript, I have n ...

pnpm may not be able to resolve dependencies

When I have my package.json file and install all dependencies with npm i, everything works fine. However, when I use pnpm i, I encounter an exception: TypeError: Cannot read property 'uid' of undefined. I don't actually use this library, so ...

Exploring Azure: Obtain a comprehensive list of application settings from a deployed Node.js web application

After successfully deploying a NodeJs app to a Linux Azure AppService, I am now aiming to retrieve the server settings of this particular app-service. By enabling managed Identity for the AppService under the 'Identity' tab, I attempted to achiev ...

AJAX request triggers Internal Server Error 500

I encountered an "internal server error 500" while trying to access a certain action. When I inspect the element, it shows "Internal Server Error 500." The functionality works perfectly on my local environment, but when deployed on the client's serv ...

Eliminating certain buttons within Ember-leaflet-draw

Is there a way to remove specific buttons from the UI in my Ember application that are used for drawing lines, circles, and polygons? I am currently using Leaflet Draw in my project. Here is a snippet of my template.hbs: {{#leaflet-map onLoad=(action &apo ...

What is the best way to divide a string into chunks of no more than 2000 characters each at the end of

Here is a brief excerpt from a string variable labeled results ... 2017-09-18 920.0100 922.0800 910.5999 915.0000 1294800 2017-09-15 924.6599 926.4899 916.3599 920.2899 2505400 2017-09-14 931.2500 932.7700 924.0000 925.1099 1397600 2017-09- ...

The height of a DIV element can vary based on

Looking at this div structure: DIV3 has a fixed height. The nested DIV5 will be receiving content from Ajax, causing its height to change. Additionally, there are some DHTML elements inside it that also affect the height. DIV5 has a fixed min-height set. ...