我尝试使用ng-repeat
绘制正确的参数来绘制图表:
这里是HTML:
<tr ng-repeat="perspective in perspectives">
<td>
<div class="hc-pie" items="values"></div>
</td>
<td>{{perspective.perfomance}}</td>
<td>{{perspective.current}}</td>
<td>{{perspective.previous}}</td>
<td>{{perspective.variance}}</td>
</tr>
和控制器:
$scope.perspectives=[
{perfomance:'AAA',
current:'a',
previous:'b',
variance:'c',
plus:false,
graphData:[
['value', 32.4],
['value', 13.2],
['value', 84.5],
['value', 19.7],
['value', 22.6],
['value', 65.5],
['value', 77.4],
['value', 90.4],
['value', 17.6],
['value', 59.1],
['value', 76.8],
['value', 21.1]
]
];
和指示:
.directive('hcPie', function () {
return {
restrict: 'C',
replace: true,
scope: {
items: '='
},
controller: function ($scope, $element, $attrs) {
},
template: '<div id="container" style="margin: 0 auto">not working</div>',
link: function (scope, element, attrs) {
var chart = new Highcharts.Chart({
chart: {
renderTo: element[0],
type: 'column',
backgroundColor: null
},
title: {
text: null
},
subtitle: {
text: null
},
xAxis: {
categories: [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
],
labels: {
enabled: false
},
gridLineWidth: 0,
minorGridLineWidth: 0,
lineColor: 'transparent',
tickLength: 0
},
yAxis: {
gridLineWidth: 0,
minorGridLineWidth: 0,
lineColor: 'transparent',
min: 0,
title: {
text: null
},
labels: {
enabled: false
}
},
tooltip: {
enabled: false
},
plotOptions: {
column: {
pointPadding: 0,
borderWidth: 0,
states: {
hover: {
color: '#FFFFFF'
}
}
}
},
legend: {
enabled: false
},
series: [{
name: 'Value',
color: '#EC5B00',
data: scope.items
}]
});
scope.$watch("items", function (newValue) {
chart.series[0].setData(newValue, true);
}, true);
}
}
});
控制台中没有任何错误,但我无法显示图表 我吃了什么?
答案 0 :(得分:1)
更新,请参阅working fiddle here
有两个错误。首先是:你的阵列没有正确关闭。第二是:你需要使用perspective.graphData而不是使用hc_pie在div中的值。 在控制器中:
UIGraphicsBeginImageContextWithOptions()
并在html中使用以下
- (UIImage *) extractImageOfSubviewFromView: (UIView *)view {
CGRect finalImageRect = CGRectMake(0, 0, view.frame.size.width, (view.lblCaption.frame.size.height + view.image.frame.size.height));
UIGraphicsBeginImageContextWithOptions(finalImageRect, NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(finalImageRect, 0, - view.header.frame.size.height);
[view.layer renderInContext:context];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return finalImage;
}