2015-10-22 18 views
8

Sto provando a inserire un diagramma alto in un contenitore flexbox. Il grafico cresce bene con il contenitore, ma non si riduce quando il contenitore si restringe.highcharts-ng cresce ma non si restringe in flexbox

Il mio progetto utilizza angularJS e highcharts-ng, anche se suppongo che il problema riguardi la stessa Flexbox. È lo stesso in Chrome e IE almeno.

Here's a plunkr che illustra il problema. Se apri la vista incorporata noterai quando ingrandisci la finestra, entrambi i grafici si riflettono per adattarsi. Ma quando lo rendi più stretto, il grafico in alto (in una flexbox) rimane invariato.

Ho inserito il pulsante di riflusso per trasmettere l'evento di riflusso per highcharts-ng, ma sembra non avere alcun effetto.

Sto cercando una soluzione alternativa o una soluzione che mi consenta di utilizzare Flexbox.

Di seguito è riportato il codice da Plunkr. È basato su un altro plunk dell'autore di highcharts-ng che ha risolto un problema simile per i contenitori bootstrap.

index.html

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

    <head> 
    <link data-require="[email protected]" 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="[email protected]" data-semver="2.1.3" src="http://code.jquery.com/jquery-2.1.3.min.js"></script> 
    <script data-require="[email protected]" data-semver="1.3.15" src="https://code.angularjs.org/1.3.15/angular.js"></script> 
    <script data-require="[email protected]*" 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="[email protected]" data-semver="4.0.1" src="//cdnjs.cloudflare.com/ajax/libs/highcharts/4.0.1/highcharts.js"></script> 
    <script data-require="[email protected]" 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' }, 
      // function to trigger reflow in bootstrap containers 
      // see: http://jsfiddle.net/pgbc988d/ and https://github.com/pablojim/highcharts-ng/issues/211 
      func: function(chart) { 
       $timeout(function() { 
       chart.reflow(); 
        // //The below is an event that will trigger all instances of charts to reflow 
        //$scope.$broadcast('highchartsng.reflow'); 
      }, 0); 
      } 
     }; 
    } 
})(); 

risposta

4

È possibile impostare 012.o flex-basis nel contenitore .main-panel per consentire a Highcharts di calcolare le dimensioni dell'elemento principale.

Ho anche rimosso il width: 100% su .highcharts-container poiché non stava facendo nulla.

L'originale Plunkr funziona su Safari 9.0.1, quindi questo potrebbe essere dovuto a differenze nel modo in cui i browser implementano le specifiche FlexBox (ad esempio related issue with width/height: 100%)

Problemi correlati