Highcharts boxplot is currently malfunctioning by presenting inaccurate values for the high and median

I am currently working on generating a box plot based on a basic set of data:

    var box_plot = Highcharts.chart(container, {

        chart: {
            type: 'boxplot'
        },

        title: {
            text: chart_title
        },

        legend: {
            enabled: false
        },
        series: [{
            name: 'Observations',
            data: [
                [1,2,3,4,5,6,7,8,9,10,11,12,13]
            ],
            tooltip: {
                headerFormat: '<em>Experiment No {point.key}</em><br/>'
            }
        }]      
    });
    return box_plot;

However, upon generating the box plot, it displays the high as 6 and median as 4 instead of the actual values in the dataset where the high is 13 and median is 6.

I would appreciate if someone could point out what I might be doing wrong. Attached are screenshots of the code and the box plot for reference.

Thank You

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

Answer №1

There are two ways to provide data to boxplot series:

  1. One way is to use an array of arrays with 6 or 5 values. The first value represents x, low, q1, median, q3, and high respectively. If the first value is a string, it will be used as the point's name and the x value will be inferred. You can also omit the x value, in which case the inner arrays should have a length of 5. Highcharts will automatically calculate the x value, starting at 0 and incrementing by 1, or based on the pointStart and pointInterval specified in the series options.

    data: [
      [0, 3, 0, 10, 3, 5],
      [1, 7, 8, 7, 2, 9],
      [2, 6, 9, 5, 1, 3]
    ]
    
  2. Another way is to use an array of objects with named values. If the total number of data points exceeds the series' turboThreshold, this option is not available. See the example below for how to structure the data:

    data: [{
      x: 1,
      low: 4,
      q1: 9,
      median: 9,
      q3: 1,
      high: 10,
      name: "Point2",
      color: "#00FF00"
    }, {
      x: 1,
      low: 5,
      q1: 7,
      median: 3,
      q3: 6,
      high: 2,
      name: "Point1",
      color: "#FF00FF"
    }]
    

If you need to perform any data calculation procedures, Highcharts does not handle this automatically. You must prepare the required data structure yourself. Here is an example:

const data = [
  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
];

const processedData = data.map((dataEl, index) => ({
  x: index,
  low: Math.min(...dataEl),
  median: dataEl[(dataEl.length - 1) / 2],
  high: Math.max(...dataEl),
  ...
}));

Check out the live demo here: http://jsfiddle.net/BlackLabel/eqz4851x/

For more information, refer to the API Reference: https://api.highcharts.com/highcharts/series.boxplot.data

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

The functionality of $state.go within $stateChangeStart in the app.run is not functioning properly in AngularJS

Having some trouble getting $state.go() function to work. The $on('$stateChangeStart'...); is functioning properly, and I can see the console message when trying to access a protected state without permission. However, the $state.go('toState ...

Circular JQuery carousel tracking

I am struggling to figure out how to create a looping effect for the images inside the slider. I would like the track to seamlessly loop around from both sides after they are hidden. Here is the link to the current jsfiddle: http://jsfiddle.net/V2x6s/3/ B ...

Obtain a particular value from a JSON file using JavaScript

My JSON file, named json.json, contains the following data: {"name1":"Hallo","name2":"Defy","name3":"Carm","name4":"Disney"} To read this file, I am using the following script: <script type='text/javascript'> $(window).load(function(){ $ ...

Data is not being saved in the database through Ajax requests

I'm currently working on developing a BlogApp and encountering a specific challenge. My Objective My goal is to retrieve the user's location using JavaScript and save it in the Model's instance in the database. While I am able to access t ...

What is the best way to arrange the elements of a dropdown list in reverse order?

I have the following code snippet used to retrieve data from a database and display it in a dropdown list: @{ int m = 1; foreach (var item in Model.MessagesList) { if (@item.receiverUserId == userId) { <li> <a class=&qu ...

Rearrange DIV elements by clicking a button that redirects you to a different webpage

Consider a scenario with two distinct pages: website.com/page1 website.com/page2 Page 1 contains multiple buttons, each leading to Page 2. On Page 2, there are various content sections (divs). Is there a straightforward meth ...

Submit form information and navigate to a different webpage without using AJAX

I need help with creating a form that redirects to another page without sending AJAX data for the current page in the action attribute. Is this possible, or is it related to PHP? const formElem = document.getElementById('form'); formE ...

Tips for utilizing onsubmit following an ajax validation check

How can I implement the onsubmit method after an ajax check? The current onsubmit function is not working. $(document).ready(function(){ $("#p_code").change(function(){ $("#message").html("<img src='ajax_loader.gif' width='26 ...

Using Three.js for 3D modeling in web development, the JSONLoader coupled

While dealing with heavy models, I am experimenting with displaying the loading percentage dynamically when loading JSON data. I conducted a basic test using the loadAjaxJSON method... The loading process shows the percentage completion, but it never reac ...

Executing a JavaScript function after making changes to a table using PHP

I have a straightforward website where JavaScript is used to gather user input and then send that data to a PHP script (the script being an external php file) through an AJAX request. The PHP script then updates the database with this information. Now, I ...

The initial call to AJAX GET may result in undefined, but it successfully retrieves data on the subsequent attempt

I am currently developing a real estate web application using ASP.NET MVC. The issue I am facing lies within the Reservations section. https://i.sstatic.net/zFgPs.png My approach involves utilizing AJAX to post data to a Controller which then returns a JS ...

What issue is being encountered with this JavaScript generated by PHP?

PHP on the host generates JavaScript code that results in an error stating: missing ; before statement The generated JavaScript code looks like this: try{ obj = document.getElementById('subcat'); }catch(e){} try{ obj.innerHTML = ...

Is there a way to ensure that a statement will not execute until the completion of a preceding function?

I am encountering an issue where the window.open function is being called too quickly, causing my other function not to finish and post in time within my onclick event. I attempted to address this by setting a timeout on the trackData() function, but it o ...

Navigating the data returned by an AJAX call can be quite perplexing

Every time a link is clicked on the website located at , an AJAX request triggers to load the content automatically. Lately, I have been encountering a perplexing piece of code injected into my response data: <script> var _q = document.createEle ...

Ensuring validity using dynamic context objects within Joi

I need to implement a dynamic validation system that involves downloading an object at runtime and saving it as a well-formed .json file. The objective is to use the values from this downloaded object as part of a validation process using Joi.validate wi ...

What could be the reason for the text not showing up?

I'm currently working on developing a "MEME Generator" but I've hit a roadblock at this stage. Whenever I: upload > Enter Text > Submit All of the JavaScript changes revert back to the default state. It seems like I might be overlooking s ...

Tips on effectively organizing information retrieved from an XML file?

I would like to organize the data in ascending order based on the DATE after making this ajax call function parseXML(xml){ var weatherArray = []; var weatherElement = xml.getElementsByTagName("forecast")[0]; weatherArray.queryTime = weatherEl ...

When using `defineModel` in Vue, the returned value can be either an object or

defineModel() is a new feature introduced in Vue 3.4+. The official documentation provides the following example: const model = defineModel() model.value = 'hello' Initially, it appears that model is an object with a value property. However, th ...

Retrieve the $http data from a function that is external to it

Apologies if the title is confusing, it's hard to explain in a different way. The situation I have is... app.controller('viewProductController', ['$scope', 'dataFactory', '$routeParams', function($scope, dat ...

"Uh oh! Encountered an error while trying to extend an unrecognized button type: copyHtml5. Here's a guide on utilizing datatables.net-buttons-bs4

I recently installed Datatables using npm and added the necessary packages: npm install --save datatables.net-bs4 npm install --save datatables.net-buttons-bs4 Now, I also want to include the buttons.html5 js file in my project. Previously, I used CDNs ...