highcharts-ng expands in flexbox without contracting

I've encountered an issue while trying to incorporate a highchart within a flexbox container. The chart expands along with the container without any problems, but it fails to contract when the container size decreases.

My current setup involves angularJS and highcharts-ng. However, I suspect that the root of the problem lies within flexbox itself as the behavior persists across both Chrome and IE browsers.

Here's a plunkr that demonstrates the dilemma. Upon widening the window, both charts adjust accordingly to fit the space. In contrast, when narrowing the window, the top chart (within a flexbox) remains static.

In my attempt to address this issue, I added a reflow button to trigger the reflow event for highcharts-ng, yet it seems ineffective.

I am in search of a workaround or any viable solution that would still allow me to utilize flexbox elements.

Provided below is the code snippet from Plunkr, which draws inspiration from another plunk by the creator of highcharts-ng, resolving a similar bootstrap container challenge.

index.html

<!DOCTYPE html>
<html ng-app="highChartTest">

  <head>
    <link data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dcbeb3b3a8afa8aebdac9ceff2eff2ee">[email protected]</a>" data-semver="3.3.2" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
    <link rel="stylesheet" href="style.css" />

  </head>

  <body ng-controller="MyHighChart as c">

    <div class="page-container">
      <div class="side-panel">
        <ul>
          <li>Item 1</li>
          <li>Item 2</li>
          <li><button ng-click="onReflowButtonPressed()" class="autocompare">Reflow</button></li>
          </ul>
        </div>
        <div class="main-panel">
             <highchart id="highchart01" config="c.config" height="300"></highchart>
        </div>
    </div>


   <highchart id="highchart02" config="c.config" height="300"></highchart>

    <script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6d071c18081f142d5f435c435e">[email protected]</a>" data-semver="2.1.3" src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
     <script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d0b1beb7a5bcb1a2febaa390e1fee3fee1e5">[email protected]</a>" data-semver="1.3.15" src="https://code.angularjs.org/1.3.15/angular.js"></script>
    <script data-require="ui-bootstrap-tpls-0.12.0.min.js@*" data-semver="0.12.0" src="https://rawgit.com/angular-ui/bootstrap/gh-pages/ui-bootstrap-tpls-0.12.0.min.js"></script>
    <script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4e262729262d262f3c3a3d0e7a607e607f">[email protected]</a>" data-semver="4.0.1" src="//cdnjs.cloudflare.com/ajax/libs/highcharts/4.0.1/highcharts.js"></script>
    <script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="325a5b555a515a534046411f5c5572021c021c0b">[email protected]</a>" data-semver="0.0.9" src="https://rawgit.com/pablojim/highcharts-ng/master/dist/highcharts-ng.min.js"></script>

    <script src="app.js"></script>
  </body>

</html>

style.css

.page-container {
  margin: 20px;
  border: 1px solid black;
  display: flex;
}

.side-panel {
  width: 200px;
  flex-shrink: 0;
  background-color: #ddd;
}

.main-panel {
  margin: 10px;
  padding: 20px;
  flex-grow: 1;
  border: 1px solid blue;
}

.highcharts-container {
  width: 100%;
  border: 1px solid red;
}

app.js

(function() {
    angular.module('highChartTest', ['ui.bootstrap', 'highcharts-ng'])
        .controller('MyHighChart', ['$scope', '$timeout', MyHighChart]);

    function MyHighChart($scope, $timeout) {

        $scope.onReflowButtonPressed = function(){
          console.log("broadcasting reflow");
           $scope.$broadcast('highchartsng.reflow');
        }
        var chartId = 'yieldColumns01';
        this.widget = {
            chartId: chartId,
            cols: '12',
            title: 'Reflow Test'
        };

        this.config = {
            options: {
                chart: { type: 'column' },
                legend: { enabled: false},
            },
            title: { enabled: false, text: ''},
            xAxis: { categories: ['A', 'B', 'C', 'D', 'E', ] },
            yAxis: { max: 100},
            series: [{
                name: '2014',
                data: [90.9, 66.1, 55.0, 53.2, 51.2]
            }],
            size: { height: '300' },
            
            func: function(chart) {
              $timeout(function() {
                chart.reflow();
             }, 0);
          }
        };
    }
})();

Answer №1

If you want to assist Highcharts in determining the parent element's dimensions, consider setting a non-relative width or using flex-basis on the .main-panel container.

I decided to eliminate the width: 100% from .highcharts-container as it seemed redundant.

The original Plunkr performed well on Safari 9.0.1, suggesting that discrepancies in browser interpretation of the flexbox specification may be at play (e.g., related issues with width/height: 100%).

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

Utilizing the Array object within AngularJS for a dynamic model

I have a specific way of storing my data as shown below: $scope.data = { name:'abc', Address:[{ Address1:'XXXX', state:'XXXX', County:'XXXX' }] } <input type="text" class="form-control" ...

Oops! Looks like there was a mistake: [ng:areq] Argument Controller is Not a Function

I'm currently working on integrating a blank Google Maps app into my Rails project with the intention of adding markers later through factories. This approach was successful in my previous project, however, I am facing difficulties getting it to load ...

Achieve a sleek, modern look by using CSS to add a border with crisp square

Hello everyone, I'm currently attempting to add a border to only one side of an a element. However, when I add the border to just one side, it creates a sharp diagonal edge: https://i.stack.imgur.com/pAqMM.png My goal is to eliminate the sharp edge ...

Is there a way to dynamically assign the background color of a webpage based on the exact width and height of the user's screen?

I have customized the CSS of my website by setting the height to 800px and width to 1050px. Additionally, I have chosen a blue background-color for the body tag. It is important that the entire application adheres to these dimensions. However, when viewe ...

How can Protractor be used to test content before Angular is fully loaded?

In my opinion, it's crucial to notify users when an Angular-based application is loading. For instance, in the case of Angular 2, you could use something like <view>Loading...</view>. I'm confident that there must be a similar method ...

Passing a service into a directive results in an undefined value

Can someone help me understand why a service I am injecting into a directive is returning undefined in certain instances? If you would like to take a look at the code, here is a plunker link: https://plnkr.co/edit/H2x2z8ZW083NndFhiBvF?p=preview var app = ...

Exploring Ways to Return to a Modal Using AngularJS and Ionic Framework

In my current project, I am faced with a challenge involving an array of items displayed on a page. Each item, when clicked, triggers a modal to open, presenting the user with a button that navigates to a separate controller and view. Upon clicking the ba ...

Is it possible to customize the deep elements of ExpansionPanelSummary using styled-components in React?

After digging into the documentation and examples on how to customize Material UI styling with styled-components, I successfully applied styling to the root and "deeper elements" within an ExpansionPanel and ExpansionPanelDetails. However, when attempting ...

Having trouble with Bootstrap v4 dropdown menu functionality?

For some reason, I cannot get the dropdown menu to work in my Bootstrap v4 implementation. I have tried copying and pasting the code directly from the documentation, as well as testing out examples from other sources on separate pages with no luck. &l ...

The scripts on Prerender.io were not loaded properly

I am facing an issue with my JavaScript files. I have two separate files: vendor.js - containing angular.js and other libraries; app.js - consisting of my own code. However, when I load them separately, the page does not open as expected during pre ...

Ways to conceal a grid item in Material UI framework

My goal is to hide a specific grid item for a product and smoothly slide the others in its place. Currently, I am using the display:none property but it hides the item instantly. I have already filtered the products and now I want to animate the hiding of ...

Utilizing CSS grid layouts to ensure images expand to fit the dimensions of the designated column and

I am currently working with a CSS grid layout that is displaying as follows: .image__gallery-grid { max-height: none; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 2.5rem; dis ...

Generating dynamic divs in parallel

Despite encountering numerous posts related to the issue at hand, none of them have solved my specific problem. I am aiming for 3 divs to display in each row, but the current code is causing each div to show up on a new line vertically: JQuery ...

Overlapping borders in Bootstrap 4 design

Working on my project with Bootstrap 4 and encountered a coding issue. Here is the code snippet: .form-info-tab { border: 1px solid #ccc; border-collapse: separate; border-spacing: 0px; padding:5px; text-align:center; } <link ...

Enhanced spacing of characters in website text

Currently working on a client's website, I find myself once again being asked by my boss (who is the designer) to increase letter-spacing in the text for aesthetic reasons. However, I strongly believe that this practice can actually lead to eye strain ...

What is the best method for arranging checkboxes in a vertical line alongside a list of items for uniform alignment?

Trying to come up with a solution to include checkboxes for each item in the list, maintaining even vertical alignment. The goal is to have the checkboxes in a straight vertical line rather than a zigzag pattern. Coffee Nestle ...

Implementing JSON data in a dropdown menu using AngularJS

When trying to read JSON data, I am encountering an issue where the dropdown list is displaying a value of 0 instead of the expected value. How can I properly read the JSON data for these dropdowns in Angular? ...

Is the code generated by Webflow.com functional and practical?

Recently, I have discovered the wonders of www.webflow.com for creating an admin layout. It excels in generating a flexbox layout based on my PSD design without requiring me to manually code with Gulp. My plan is to further simplify the process by breaki ...

Guide on dynamically accessing child records of a Firebase array in Angularfire

I'm in the process of setting up an accordion using angularfire. I've managed to fetch the main categories ("A1", "D1", "R1") for display, but I'm struggling to retrieve the child elements for each selected accordion tab. For example, if I s ...

Is it possible to use npm to create an AngularJS project?

Is it possible to create an AngularJS project structure using npm or any other commands? Just like we use the following command to create a new angular project: ng new application_name Similarly, for creating a new react app we use: npx create-react-app ...