Adjusting the Height of Highcharts Funnel Segments to a Specific Measurement

My current funnel setup looks like this:

$(function () {
    var dataEx = [
                ['1 Visit', 352000],
                ['2 Visits',       88000],
                ['3+ Visits',       42000]
            ],
        len = dataEx.length,
        sum = 0,
        minHeight = 0.05,
        data = [];
    
    for(var i = 0; i < len; i++){
        sum += dataEx[i][1];
    }
    
    for(var i = 0; i < len; i++){
        var t = dataEx[i],
            r = t[1] / sum;
        data[i] = {
            name: t[0],
            y: ( r > minHeight ? t[1]  : sum * minHeight ),
            label: t[1]
        }
    }
    $('#container').highcharts({
        chart: {
            type: 'funnel',
            marginRight: 100,
       
        
          events: {
        load: function() {
          var chart = this;
          Highcharts.each(chart.series[0].data, function(p, i) {
            p.dataLabel.attr({
              x: (chart.plotWidth - chart.plotLeft) / 2,
              'text-anchor': 'middle'
            })
          })
        },
        redraw: function() {
          var chart = this;
          Highcharts.each(chart.series[0].data, function(p, i) {
            p.dataLabel.attr({
              x: (chart.plotWidth - chart.plotLeft) / 2,
              'text-anchor': 'middle'
            })
          })
        }
      },
        
       },  
      
        title: {
            text: 'Guest Return Funnel',
            x: -50
        },
        tooltip: {
            //enabled: false
            formatter: function() {
                return '<b>'+ this.key  +
                    '</b> = <b>'+ Highcharts.numberFormat(this.point.label, 0) +'</b>';
            }
        },
        plotOptions: {
            series: {
            
            allowPointSelect: true,
            borderWidth: 12,
            animation: {
                duration: 400
            },
                dataLabels: {
                    enabled: true,
                    connectorWidth:0,
                    distance: 0,
                    formatter: function(){
                      var point = this.point;  
                        console.log(point);
                      return '<b>' + point.name + '</b> (' + Highcharts.numberFormat(point.label, 0) + ')'; 
                    },
                    minSize: '10%',
                    color: 'black',
                    softConnector: true
                },
                neckWidth: '30%',
                neckHeight: '0%',
                width: '50%',
                height: '110%'
            }
        },
        legend: {
            enabled: false
        },
        series: [{
            name: 'Unique users',
            data: data
        }]
    });
});
<script src="https://code.jquery.com/jquery-3.3.1.min.js"
  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  crossorigin="anonymous"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/funnel.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>


<div id="container" style="width: 600px; height: 400px; margin: 0 auto"></div>

In my current setup, the first piece of the funnel is significantly larger than the rest. I am looking to set a fixed height for all pieces while adjusting their widths based on values. This means that the width will decrease from top to bottom, but the height remains constant.

Is there a way to achieve this?

Answer №1

The data used in a funnel chart type only affects the height of the point. Take a look at this example for more clarification: http://jsfiddle.net/BlackLabel/pdsL5uyq/

If you want to maintain a fixed height for the pieces, ensure that you have the same values in the data set. To adjust the width of the elements, you can utilize the properties 'neckWidth' and 'width'.

To understand the exact functioning, refer to the Funnel source code here:

Highcharts.chart('container', {
  series: [{
    type: 'funnel',
    data: [10, 10, 10],
    neckWidth: 50,
    neckHeight: 0,
    width: 200,
    dataLabels: {
      format: "{point.y}"
    }
  }]
});

For detailed documentation, visit: https://www.highcharts.com/docs/chart-and-series-types/funnel-series

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

Bring in 2 Angular applications into a different JavaScript project

In my current setup, I have 2 distinct Angular projects. To build each project, I execute the following CLI command: ng build --prod --output-hashing=none Following this command, the build process generates the below files for each project: runtime.js ...

Can you explain the significance of this specific form of variable declaration?

Have you ever been in a situation where you receive some code that actually works, but you're not sure how it's working? For example, what exactly does this declaration method accomplish? const { actions: { createRole, updateRole } = {} } = prop ...

What is the best way to prevent the content within a div from being obscured by a sticky element affixed to the bottom of the div?

I am struggling with ensuring that the content in my wrapper does not get cut off by the "view more" div attached to the bottom. The default wrapper cuts off the children, and even when expanded, the issue persists due to CSS problems. In React, the gener ...

Deciphering the Structure of Robot Log File (log.html)

Just starting out with Robot framework and I'm looking to tweak the output of log.html that's generated after running test suites. After examining the source code of log.html, I discovered that this line is responsible for adding the test execut ...

Tips for personalizing the Material-UI sticky header to work with horizontal scrolling

Check out this example of a Material UI table with a sticky header on CodeSandox: https://codesandbox.io/s/yi98d?file=/demo.tsx I encountered an issue where the left side header cells slide behind each other when I added a stickyHeader prop to the Materia ...

The automated linting process through npm script did not meet the desired expectations

I need help setting up a script that will automatically fix all files in my Vue project like this: "lint": "eslint --fix vue/**/*.vue && eslint --fix vue/**/*.js" The goal is to automatically lint all .vue and .js files within the project. Unfor ...

Displaying a Dynamic Loading Animation While Making an AJAX Call with jQuery

When a user clicks on the active status button, it should switch to inactive with a red color, and vice versa. Currently, I can update my status in the backend, but I have to refresh the page to see the changes every time! My requirement is that during t ...

Most effective method for waiting for a dropdown to load and choosing a value using Selenium in JavaScript

My current task involves interacting with a website built in React using Selenium to choose a value from a dropdown menu. Given that the website is built in React, I understand that waiting for the DOM to be ready may not always work as expected, but I st ...

Obtain the identification address for a group of items

I have a JSON object containing place IDs, and I am attempting to retrieve the corresponding addresses for each ID. This is the code snippet I'm using: <div id="places" class="places"></div> <script> function initialize() { j ...

Every character entered in JSP should trigger an instant retrieval of the corresponding string in the servlet

Having a JSP file that contains a text field: <form action="someServlet" method=post> <input type ="text" name="user" id="uname"> <button type="submit" id="submit">Submit</button> </form> When typing each letter in the JSP, ...

Send the dynamically created password variable from the server to the client-side

I'm attempting to transfer the password variable that I've generated to my front-end. The issue seems to be that I am generating the password inside the route.post This snippet is from my fileUpload.route.ts router.post('/upload-file&a ...

Using @react-three / react-three-fiber: Implement useLoader() to dynamically load a new file when props are updated

Presently, I have a functional react component that loads a gltf model during initial load. The path is passed through the props and this setup seems to be working well. However, when the props change and trigger a rerender of the component, I noticed tha ...

Fetching the link and heading using beautifulSoup from the <a> elements

I am in the process of creating a script that will extract all the links from the div elements with a class of "pntc-txt." After that, I plan to retrieve the href attribute and the text within the <a> tags. This data will then be inserted into a da ...

Is it possible for jQuery to create two separate variables with identical names?

When it comes to declaring variables in jQuery, you have 2 different options: The jQuery method The JavaScript method Are these two statements equivalent: $variable = "string"; And: var variable = "string"; Or do they create separate variables? ...

Encountering a 403 error while attempting to install Meteor with npm using the command npm install -

Following the installation instructions provided on the official Meteor website at , I encountered an error while trying to install Meteor using the command "npm install -g meteor". Here is the detailed error message: os  win 10 pro node -v  v14.15.1 n ...

The express route parser is incorrectly detecting routes that it should not

I am encountering an issue with the following two routes: router.get('/:postId([0-9]*)', handler) router.get('/:postId([0-9]*)/like', handler) The first route is intended to only capture URLs like /posts/4352/, not /posts/3422/like. ...

A guide on organizing an array of objects by a specific property using a separate array

Here is the array I am working with: var arr = [ { count: 27, dataRil: "08/06/21", subCateg: "FISH", }, { count: 22, dataRil: "08/06/21", subCateg: "DOG", }, { count: 28, dat ...

Why is npm attempting to compile a previous version of my code?

Being a complete newbie to npm and node.js, I hope you can bear with me if I'm lacking in providing the right details. I am working on developing a plugin for a website that utilizes an out-of-the-box framework within npm. Initially, everything was ru ...

Error encountered in NextJS: Trying to call res.unstable_revalidate which is not a function

I recently tried out a cutting-edge feature introduced in NextJS v.12.1 . The API itself is functioning correctly and can be accessed. However, I encountered a 500 error with the message res.unstable_revalidate is not a function. This issue persisted wheth ...

Is there a way to change the color of a checkbox (both the box and font) in the disabled state using material ui

When using Material UI v4.9.12, it is possible to create a customized checkbox with a specific color that remains fixed: const GreenCheckbox = withStyles({ root: { color: green[400], '&$checked': { color: green[600], }, ...