"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.

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:

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

Updating select option values without reloading the page using a modalHere is an efficient method for updating

Is there a way we can update the select tag option values without having to reload the page after submitting data in the bootstrap modal? Currently, we are facing an issue where the submitted values do not show up in the option tag until the page is reload ...

Executing TipTap commands from a script tag in Vue 3: A step-by-step guide

One of the components I'm working with includes the following: <button @click="$refs.image.click(); editor.chain().focus().setImage({ src: state.image }).run()"></button> <input type="file" ref="image" sty ...

Collapsing or expanding the Material UI accordion may lead to flickering on the page

import React from "react"; import { makeStyles } from "@material-ui/core/styles"; import Accordion from "@material-ui/core/Accordion"; import AccordionDetails from "@material-ui/core/AccordionDetails"; import Accordi ...

Trigger a function when the browser automatically populates an input field

I am attempting to trigger a function that can detect if the browser has autofilled a field and then add a specific class to it. After finding a thread with a solution that mostly works, mentioned here: Here is how I implemented it: $.fn.allchange = fun ...

Exploring the dynamic world through HTML5 canvas and animated objects

Today I am exploring HTML 5 canvas and experimenting with moving 3 circles on the canvas. Based on my research, it looks like I need to continuously redraw the circles (perhaps every 60 milliseconds) and clear out the old circle before rendering the new on ...

When working with React JS and the react-select library, I am looking to automatically reset the options to their default value once

I am attempting to disable the select list after unchecking the checkbox and resetting the select value back to default, but currently it is retaining the last selected option. I am utilizing React-select for the select and options in this scenario. APP.j ...

Orchard's TinyMce now supports a drop event with jQuery integration

Currently in the process of constructing a website using Orchrad. I have implemented the tinymce4 html editor for building landing pages without any issues thus far. However, my current challenge involves capturing the jQuery drop event within the TinyMce ...

Is it possible to clear a div using jQuery and then restore its contents?

In my setup, I have a video player within a div where clicking the play button (.video-play-container) fades in the video, and clicking the close button (.close-video) fades it out. The issue arose when the faded-out video continued playing in the backgr ...

Importing GeoJSON data into Meteor's Leaflet

Recently diving into Meteor, I am on a mission to create my own customized version of this impressive example from leaflet incorporated into Meteor: Interactive Choropleth Map The implementation requires the use of this GeoJson Data file: us-states The o ...

Access basePath within the Next.js AppRouter

Is there a way to access the basePath in Next.js 13 when using AppRouter? To retrieve it, we can simply get router.basePath through the useRouter hook of PageRouter by importing `import { useRouter } from 'next/router' I am currently unable to ...

Vue and Nuxt: Concealing a Variable in .env File Post-Build

     Within my Nuxtjs project, I have implemented a process in which I encrypt requests before they are sent to my Laravel API. Once the response is received, I decrypt it using specific global functions that have been defined... function encryptDataLa ...

Multiple onClick events being triggered unexpectedly upon component re-render

My react component is a form that triggers a function to handle data saving and other tasks when the send/submit button is clicked. The issue arises when the component seems to re-render multiple times after the button click, most likely due to updated ex ...

Contrast in executing an Arrow Function versus a regular Function when passing them as Props in REACTJS

Here is the component code: <SelectCampanha titulo="Preenchimento obrigatório" listaOpcoes={ category ? riskModel.filter((item) => item.CategoryType.includes(categoria) ...

Guide on properly documenting custom function types in JSDoc or TypeScript to ensure accurate referencing for VSCode IntelliSense functionality

I am currently working on documenting custom function types within an object and would greatly appreciate any assistance: A Closer Look at the Issue Consider this basic object declaration with several function properties (addCoordinate, addCoordinateOne, ...

What is the best way to retrieve an object from every function?

I'm dealing with a <div> containing radio buttons: <div id='RB-01'> <span>Item_1</span><input type='radio' name='RB01' value='1'><br /> <span>Item_2</span><inp ...

Output the name of the file while executing the ant process

Currently, I am utilizing YUI compressor within an ant build process to compress CSS and JavaScript files. I would like the compressor to display the name of each file it is processing as it goes along, so that in case of an error, I can easily pinpoint wh ...

What's the best way to update the value of a TextInput field?

Previously, I was updating the text input using local state. Here's an example: state = {name: ''} ... <AddEditFormInputs onChangeText={name => this.setState({ name })} textStateValue ...

How to stop crosshair line at the intersection point of x and y axes on a line graph using Highcharts

I feel like using an image would help better illustrate my question. https://i.stack.imgur.com/LJN12.png Whenever I enable crosshairs, they extend from the bottom of the chart to the top. Is there a way to create a crosshair that only intersects at the x ...

Comparison between PHP's JSON parser and Javascript's JSON parser

Can anyone help me with this PHP serialize JSON encoding issue? json_encode(array('pattern' => '^(?:/?site/(?[\w\-]+))?(?:/?intl/(?[a-z]{2}(?:\-[a-z]{2})?)/?)?(/?(?.*))')); // output json: {"pattern":"^(?:\/?site ...

AngularJS - ng-repeat not updating when property array changes

I have a loop in my HTML using ng-repeat: <div class="row"> <div ng-repeat="item in model.painel track by item.codigoIncidente"> <strong>{{item.restante.horaMinutoSegundo}}</strong> </div> </div> In ...