我正在尝试根据图表中显示的水平条的数量动态更改图表的高度。
我使用ng-style动态传递css。如果我不渲染图表,ng-style工作正常(http://jsfiddle.net/7veB2/)。
链接(http://jsfiddle.net/gsthilak/atwyh073/)有一个水平方式的工作高图条形图。
我正在尝试在id ="容器"中呈现图表。在下面的JSFiddle链接中,但它不呈现图表。
JSFiddle(不工作)链接:http://jsfiddle.net/gsthilak/7veB2/19/
我正在尝试动态更改图表的高度,因为如果小空间内有太多条形图,则图表看起来很狭窄。
JS代码看起来像:
var app = angular.module('myApp', []);
function ctrl($scope){
$scope.myStyle= {
"width":"900px",
"background":"red"
}
$scope.chartHeight = 400+"px"
$scope.chartStyle = {
"height":$scope.chartHeight,
"margin":"0 auto",
"min-width":"310px",
"max-width":"624px"
}
}
var baseValue = 0;
var shadowBaseValue = 0;
var outputTitle = "Net Sales";
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
credits: {},
exporting: {},
legend: {},
title: {
text: outputTitle
},
subtitle: {
text: "MM $"
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
formatter: function () {
var index = this.series.chart.xAxis[0].categories.indexOf(this.x);
if (this.series.userOptions.labels === undefined) {
return this.y + baseValue;
}
return this.key === "Combined Uncertainty" || this.key === "" ? "" : this.series.userOptions.labels[index];
}
}
}
},
xAxis: {
title: {
text: 'Factor'
},
allowDecimals: false,
categories: ['Annual Revenue', 'Number of Years', 'Annual Costs', 'Combined Uncertainty', '']
},
yAxis: [{
title: {
text: 'MM $'
},
labels: {
formatter: function () {
return this.value + baseValue;
}
}
}],
series: [{
threshold: 29.5,
name: 'Low',
grouping: false,
type: 'bar',
data: [{
x: 0,
y: 12.15 - baseValue,
}, {
x: 1,
y: 15.45 - baseValue,
}, {
x: 2,
y: 31.25 - baseValue,
}, {
x: 3,
y: 12.15 - baseValue,
}],
labels: [10, 5, 1, 2]
}, {
threshold: 29.5,
name: 'High',
grouping: false,
type: 'bar',
data: [{
x: 0,
y: 46.86 - baseValue,
}, {
x: 1,
y: 42.28 - baseValue,
}, {
x: 2,
y: 27.77 - baseValue,
}, {
x: 3,
y: 46.86 - baseValue,
}],
labels: [30, 10, 3, 4]
}]
});
HTML代码如下:
<div ng-app="myApp" ng-controller="ctrl">
<div id="container" ng-style="chartStyle"></div>
<div style="width: 250px; overflow: scroll; " >
<div ng-style="myStyle">Hello!</div>
</div>
</div>
请帮我解决这个问题。谢谢!