Highcharts is not effectively adapting to the responsiveness of all series in the chart

I'm currently working on a responsive chart that features a dynamic text box positioned next to the chart itself. This text box updates with new information each time I hover over data points on the chart.

Interestingly, the text box functions perfectly on smaller screens when hovering over the first data set. However, it fails to update or display properly when hovering over the second and third sets of data.

If you'd like to see for yourself, check out this live demo: http://jsfiddle.net/b0u10ndw/

Below is the code snippet responsible for the responsive behavior:

    responsive: {
        rules: [{
            condition: {
                maxWidth: 500
            },
            chartOptions: {
                legend: {
                    align: 'center',
                    verticalAlign: 'bottom',
                    layout: 'horizontal'
                },
                series: { point: {  events: { mouseOver: function ()    {
                                 var chart = this.series.chart;
                                if (!chart.lbl) {
                                chart.lbl = chart.renderer.label('')
                                .add();
                                }
                                chart.lbl
                                    .show()
                                    .css({ width: '80' })
                                    .attr({ text: 'this is the text and I have to make it really long so that it goes for multiple lines' });
                                        chart.lbl.align(Highcharts.extend(chart.lbl.getBBox(), {
                                                align: 'right',
                                                x: 0, // offset
                                                verticalAlign: 'top',
                                                y: 50 // offset
                                                }), null, 'spacingBox');
                                }

                    } } },

To observe the issue in action, simply resize the chart to a smaller size and hover over each bar one by one.

Although I attempted to set the width of the text box as a percentage, it appears that only pixel units are being accepted at this time.

Answer №1

The chart is functioning correctly as per the provided documentation.

An interesting scenario involves configuration objects that accept arrays, such as xAxis, yAxis, or series. In these cases, an id option is utilized to link the new set of options with an existing object. If no existing object with the same id is found, the first item is updated instead. For instance, if you set chartOptions with a series item lacking an id, it will result in updating the chart's initial series.

refer to: responsive.rules

The resolution (Sergiu's solution also works) involves defining events within the plotOptions.column object.

 plotOptions: {
        column: {
          point: {
            events: {
              mouseOver: function() {
                ...
              }
            }
          }
        }
      },

example: http://jsfiddle.net/b0u10ndw/1/

I specified options in plotOptions.column instead of plotOptions.series (which seemed more logical), but this choice resulted in an error (reported bug here).

For Sergiu's example on allowPointSelect - it is necessary to link the series using ids:

In chart options:

series: [{
        name: 'Christmas Eve',
        data: [1, 4, 3],
        id: 's1'
    }, {
        name: 'Christmas Day before dinner',
        data: [6, 4, 2],
        id: 's2'
    }, {
        name: 'Christmas Day after dinner',
        data: [8, 4, 3],
        id: 's3'
    }],

In responsive rules:

 series:[{
                        allowPointSelect:true,
                      id: 's1'
                    }, {
                        allowPointSelect:true,
                      id: 's2'
                    }, {
                        allowPointSelect:true,
                      id: 's3'

example: http://jsfiddle.net/hsd19y0y/3/

Answer №2

It seems that the series object override may not be fully supported. I conducted a test using the responsive demo on Highcharts and encountered similar issues when attempting to override a simple property for the series object. Here is the link to the test

Upon resizing the chart, the allowPointSelect property was only overridden for the first column in each group, as demonstrated in the provided demo.

A similar behavior was observed in your example as well. By setting different texts for the normal mouseOver event and the one specified in the responsive object, it became evident that the responsive declaration event would only trigger for the first column in each group. You can view this here: http://jsfiddle.net/kokup8sx/

To achieve the desired outcome, consider modifying the main mouseOver event handler to execute different actions based on this property:

chart.chartWidth

One possible approach could involve:

mouseOver: function () {
    var chart = this.series.chart;
    if (!chart.lbl) {
        chart.lbl = chart.renderer.label('').add();
    }

    if (chart.chartWidth < 500) {
        chart.lbl.show().css({ width: '80' }).attr({ text: 's-this is the text and I have to make it really long so that it goes for multiple lines' });
        chart.lbl.align(Highcharts.extend(chart.lbl.getBBox(), {align: 'right', x: 0, verticalAlign: 'top', y: 50}), null, 'spacingBox');
    } else {
        chart.lbl.show().css({ width: '180' }).attr({ text: 'l-this is the text and I have to make it really long so that it goes for multiple lines' });
        chart.lbl.align(Highcharts.extend(chart.lbl.getBBox(), {align: 'right', x: 0, verticalAlign: 'top', y: 50}), null, 'spacingBox');
    }
}

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 to tilt text at an angle inside a box? CSS can help achieve that effect!

Hey there, is it possible to achieve this with CSS or JavaScript? I require it for a Birt report. ...

Unlock the lightbox and send the user to the parent page

Is there a way to simultaneously launch a lightbox popup and redirect the parent page? I have an AJAX script that retrieves HTML content as a response. My goal is to display this content in a lightbox popup while also directing the parent window to a des ...

Ways to create a gradual movement for a div upon toggling a class

$(document).ready(function(){ $("#toggle-btn").click(function(){ $(".book").toggleClass("with-summary",1000); }); }); .book { height:500px; width:100%; position: relative; border:1px solid red; } .book-summary { position: absolute; lef ...

JQuery fixed div bounces unpredictably when scrolling

Currently, I have a scenario on my webpage where there is a div called RightSide positioned on the far right side below another div named TopBanner. The TopBanner div remains fixed at the top of the screen even when the user scrolls down, which is exactly ...

Addressing the issue of missing data in JSON documents

Currently, I'm dealing with a situation where my JSON data contains values that are "NULL" from the database. The problem is that these NULL values are being returned as actual NULL values in the JSON response, but I don't want my users to see th ...

I have a question regarding the CSS universal selector

I've been working on developing a website, but I'm having trouble with the universal selector. No matter how many times I try, it just won't work. If you'd like to see an example of what I'm dealing with, check out this link: https ...

Updating website links in real time with the power of jquery

Is there a way to dynamically change the parameter of a link? For example: Link1 Link2 Link3 By default, their URL is ?item=text, so link1 would be href="?item=link1", etc. But when I click on link1, the URLs of link2 and link3 should change to include ...

Send submitted form field arrays to the database

I am currently developing a sewing management app that includes an order page where users can place multiple orders. However, all orders need to be invoiced with one reference code. On the first page, I collect basic details such as pricing, and on the nex ...

Obtain text content from a disabled textbox with Selenium

I am currently working with a text box that displays hours ranging from 1 to 24. The hours can be increased or decreased by clicking on Up and Down Arrows (Hyperlinks) located above and below the text box. Below is the code for my text box: <input typ ...

Struggling to make changes to a Styled Component in a React application

In a certain file, I have a BaseComponent composed of various other components and being exported. The top level of the BaseComponent contains a wrapper responsible for managing margins. When I export it and attempt to override some styles with: //other fi ...

A margin is set on a div element that occupies 100% width and 100% height, nestled within another div element also occupying 100% width and

As I work on constructing a website with a video background, my goal is to ensure that all divs are centered and responsive by setting the width and height to 100%. Additionally, I have implemented an overlaying div that fades in and out upon clicking usin ...

Do AJAX-inserted elements cause a delay in the loading of the DOM? How is the loading of the DOM determined

Is the loading time of the DOM delayed if a page executes Javascript upon loading which inserts new elements via AJAX? Our UI relies on jQuery's "ready" function to function after the DOM is loaded, and we hoped that inserting page elements asynchron ...

disable event listeners on the DOM

I am currently developing a web framework and focusing on integrating XSS prevention measures. I have successfully implemented data escaping for database storage, but now I am faced with the challenge of allowing users to save generated HTML without riskin ...

The height attribute is not functioning properly in Mozilla Firefox

I am facing an issue on my website where I set the height of the body tag to 1460px. It works perfectly on Chrome and IE, but there are problems on Firefox. See my code below: body { background-image: url('../images/background.jpg&apos ...

Is there a way in CSS to apply multiple colors to individual letters within a word?

Is it possible to add random colors to every pixel of a letter or multiple colors to a letter using CSS? Check out this example. ...

What is the best way to adjust the size of carousel images within a box element?

How can I ensure that carousel pictures are displayed clearly within the box without overflowing? The code I tried resulted in the pictures overflowing from the box and not being visible clearly. How can I resolve this issue? .container { width: 1490px; ...

Tips for retaining the hashed links' rel attribute when the page refreshes

I am in need of assistance with this issue. Below is the code I have been working on: $('.Ajax_links').click(function() { window.location.hash = $(this).attr("href"); var href = $(this).attr('href'); $('#contaniner_div ...

Toggle visibility of div content when hovering over a link by leveraging the data attribute, with the div initially visible

I have a collection of links: <p><a href="#" class="floorplan initial" data-id="king"><strong>King</strong></a><br> 4 Bedrooms x 2.5 Bathrooms</p> <p><a href="#" class="floorplan" data-id="wood">< ...

The implementation of classList.toggle in my JavaScript code is not functioning as expected

I created a button that toggles the visibility of a div. It works fine the first couple of times, but then it stops working. When I click on column1, the hidden div inside column1 doesn't appear. But when I click on column2, the hidden div inside colu ...

Efficiently loading images into a navigation flyout: the ultimate guide

I have a large navigation flyout menu that includes images to display the items. Although it is functioning properly, I have noticed that the page load time is a bit slow due to the higher number of images being loaded. Here is an example of my code: &l ...