根据移动设备屏幕大小动态设置HighCharts marginTop

时间:2016-04-12 10:58:08

标签: javascript angularjs highcharts ionic-framework

如何根据当前窗口高度动态设置marginTop

E.g。

$scope.chartConfig = {
  options: {
    chart: {
      type: 'solidgauge',
      // set to -50 if window height is 700px...
      // set to -20 if window height is 500px...
      marginTop: -50
    }
  }
}

1 个答案:

答案 0 :(得分:1)

这是我解决它的方式:

function ChartController($scope, $window) {
  $scope.chartConfig = {
    options: {
      chart: {
        type: 'solidgauge',
        // set to -50 if window height is 700px...
        // set to -20 if window height is 500px...
        marginTop: 0
      }
    }
  }

  if ($window.innerHeight >= 568 && $window.innerHeight <= 639) {
    $scope.chartConfig.options.chart.marginTop = -95;
  }
}