我有几个图表使用highcharts插件和指令,以及通过我的应用程序使用ng-grid的表格。在查看主页后直接查看带有图表或表格的页面时,图表和表格不考虑其框架宽度,并扩展到1900px的宽度(参见图像:http://i.imgur.com/6uDrZBc.png?1)。刷新页面一次后,图表和网格就应该适合它们的框架。可能导致这个问题的原因是什么?
下面的代码,让我知道是否有任何其他代码会有所帮助。感谢。
其中一个违规网页的HTML:
<div class="col-md-7" id="chart">
<div class="panel panel-default">
<div class="panel-heading" ng-init="isCollapsed = false">
<div class="panel-title">
Top 8 Drugs by 2013 Revenue
<button class="pull-right btn btn-xs" ng-click="isCollapsed = !isCollapsed"><span
class="text-center"
ng-class="{'fa fa-plus': isCollapsed, 'fa fa-minus': !isCollapsed}"></span></button>
</div>
</div>
<div class="panel-body" collapse="isCollapsed" ng-if="Revenues[0].evaluate_productRevenue2013 > 0">
<div class="col-xs-12" ng-cloak>
<highchart id="company-chart-overview-1" config="chartConfig"></highchart>
</div>
<div class="row-fluid col-xs-offset-5">
<div class='my-legend'>
<div class='legend-title'>RxScore Safety Indicator </div>
<div class='legend-scale'>
<ul class='legend-labels'>
<li><span style='background:#008000;'></span>Low</li>
<li><span style='background:#FFFF00;'></span></li>
<li><span style='background:#E69628;'></span></li>
<li><span style='background:#FF0004;'></span>High</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
Highcharts config:
exports.getOverviewChart = function(RevenueSlices){ var companyName;
var Series = [
{name: 'Revenue ($MM USD)', data: [], type: 'column'}
];
var cCategories = [];
var colors = ['green', 'yellow', '#CD7D0F', 'red'];
var thresholds = [47.17, 55.81, 61.83, 82.83];
var cleanSlices = _.reject(RevenueSlices, function (sl) {
return sl.BrandName === "Unknown";
});
cleanSlices = _.filter(cleanSlices, function (cs) {
return Math.abs(cs.evaluate_productRevenue2013) > 0;
});
angular.forEach(cleanSlices, function (o) {
var s = Math.abs(o.metric_rxscore);
var color;
if (s >= thresholds[2]) {
color = colors[3];
} else if (s >= thresholds[1]) {
color = colors[2];
} else if (s >= thresholds[0]) {
color = colors[1];
} else if (s >= 1) {
color = colors[0];
} else {
color = 'lightgrey';
}
companyName = o.parent;
cCategories.push(o.BrandName);
Series[0].data.push({name: o.BrandName, color: color, y: Math.abs(o.evaluate_productRevenue2013)});
});
var overviewChart = {
options: {
chart: {
type: 'StockChart'
}, legend: {
enabled: false
},
exporting: {
enabled: false
},
plotOptions: {
series: {
stacking: ''
}
}
},
size: {
// width: 573,
height: 380
},
xAxis: {
title: {
text: 'Drug'
},
categories: cCategories
},
yAxis: {
title: {
text: '2013 Revenue'
},
labels: {
format: '{value} $MM USD'
}
}, credits: {
enabled: false
},
series: Series,
title: {
style: { 'display': 'none' }
}
};
return overviewChart;
};
ng-grid选项:
var tmp = companyChartService.getOverviewChart(Revenues.slice(0, 8));
$scope.colDefs = companyGridService.getColDefs();
$scope.ToolTipper = tooltipService.getTooltip;
$scope.colDefs = companyGridService.getColDefs();
$scope.myData = Revenues;
$scope.gridOptions = {
data: 'myData',
enableSorting: true,
enableColumnResize: true,
showGroupPanel: true,
enableCellGrouping: true,
showColumnMenu: true,
enablePinning: true,
showFilter: true,
jqueryUITheme: true,
//cellClass: 'drugName',
columnDefs: 'colDefs'
//rowClass: 'drugName'
};
答案 0 :(得分:0)
此问题是由使用ng-class指令应用的错误css规则引起的。直到新状态加载后才删除css,因此即使它不可见,也会影响ng-grid和highcharts用来确定其大小的页面宽度。在重写css并删除ng-class之后,问题就解决了。
此处的ng-grid教程http://ui-grid.info/docs/#/tutorial/108_hidden_grids突出显示了针对具有类似问题的人的另外几种可能的解决方案:
- 为网格指定特定的高度和宽度,如下例所示。
- 使用ng-if防止网格被渲染,直到它所在的元素(tab / accordion / etc)处于活动状态,就像在此plunker中一样。
- 使用autoResize功能让网格根据需要重绘。这可能会导致一些闪烁,因为检查是在250ms周期。 这是一个展示这一点的掠夺者。
醇>