我以饼图中的数据点所需的确切形式返回数据(scope.myData与scopes中的数据相同)....但值不显示在饼图...但如果我在var中给相同的json格式并将其分配给数据点它的工作正常(scope.s)...我不明白为什么?我无法使用json响应来显示动态饼图,使用canvas.min.js和angularjs
<!DOCTYPE html>
<html data-ng-app="myapp">
<head>
<meta charset="ISO-8859-1">
<title>AngularJS Tutorial</title>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js">
</script>
<script>
var app = angular.module('myapp',[ ]);
app.controller('HelloWorldController', function($scope, $http){
var res = $http.get('http://localhost:8088/api/user/');
res.success(function(data, status, headers, config) {
$scope.myData = data;
});
res.error(function(data, status, headers, config) {
alert("failure message: " + JSON.stringify({data: data}));
});
$scope.s= [{"y":1,"legendText":"DB
check","label":"DB","color":"green"},{"y":1,"legendText":"F
check","label":"Folder","color":"red"}]
$scope.chart1 = new CanvasJS.Chart("chartContainer",
{
title:{
text: "Statistics of health check "
},
animationEnabled: true,
legend:{
verticalAlign: "center",
horizontalAlign: "left",
fontSize: 20,
fontFamily: "Helvetica"
},
theme: "theme2",
data: [
{
type: "pie",
indexLabelFontFamily: "Garamond",
indexLabelFontSize: 20,
indexLabel: "{label} {y}%",
startAngle:-20,
showInLegend: true,
toolTipContent:"{legendText} {y}%",
dataPoints:$scope.myData //This is where problem lies
}
]
});
$scope.chart1.render();
});
</script>
<script type="text/javascript"
src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</head>
<body data-ng-controller="HelloWorldController">
<h1>You selected:
{{myData}}
</h1>
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
</body>
</html>
你可以做'$ scope.myData'及的控制台日志检查什么是它的输出? –
似乎您在图表后获得API响应。你可以把console.log for myData。 – NNR
其打印未定义为console.log – rahul