嗨即時嘗試有一個網頁,顯示政客的推文情緒。我正在爲情緒統計創建一個圖表。我正在使用Zingchart,我可以創建靜態數據,但我無法創建動態數據。如何使用動態數據創建AngularJS圖表
這是我用來插入靜態數據與數組chartdata的代碼。
<div class="row">
<div class="col-sm-12">
<div ng-init="chartdata = [[1167],[456],[990]]">
<zingchart id="chart-1" zc-values="chartdata" zc-json="myJson"
zc-width="100%" zc-height="568px"></zingchart>
</div>
</div>
</div>
它工作正常,像這樣的,但我想從我的angularjs而不是靜態值使用的數據。 例如:我試着做這樣的事情,但它不工作
<div class="row">
<div class="col-sm-12">
<div ng-init="chartdata =[[{{politicianData.stats.total_positive}}],[{{politicianData.stats.total_negative}}],[{{politicianData.stats.total_neutral}}]]">
<zingchart id="chart-1" zc-values="chartdata" zc-json="myJson" zc-width="100%" zc-height="568px"></zingchart>
</div>
</div>
</div>
如何從角控制器得到的承諾陣列數據中的數據?
這是我的政客控制器:
angular.module('myapp')
.controller('PoliticianController', function($scope, PoliticianData, Politician, searchService, utilService) {
var politicianData = new Politician(PoliticianData);
politicianData.$promise.then(function (result) {
$scope.politicianData = result;
});
$scope.myJson = {
globals: {
shadow: false,
fontFamily: "Verdana",
fontWeight: "100"
},
type: "pie",
backgroundColor: "#fff",
legend: {
layout: "x5",
position: "50%",
borderColor: "transparent",
marker: {
borderRadius: 10,
borderColor: "transparent"
}
},
tooltip: {
text: "%v requests"
},
plot: {
refAngle: "-90",
borderWidth: "0px",
valueBox: {
placement: "in",
text: "%npv %",
fontSize: "15px",
textAlpha: 1,
}
},
series: [{
text: "Positive",
backgroundColor: "#FA6E6E",
}, {
text: "Negative",
backgroundColor: "#D2D6DE"
}, {
text: "Neutral",
backgroundColor: "#28C2D1"
}]
};
});
這是politician.html頁
<span>{{politician.first_name}} {{politician.last_name}}</span>
</td>
<td>{{politicianData.stats.total}}</td>
<td>{{politicianData.stats.twitter.total}}</td>
<td>{{politicianData.stats.rss.total}}</td>
<td>{{politicianData.stats.total_negative}}</td>
<td>{{politicianData.stats.total_positive}}</td>
<td>{{politicianData.stats.total_neutral}}</td>
PoliticianData.stats.total_positive正確顯示計數我想要使用與我的圖表相同的數據作爲輸入值。 我該怎麼做?
您好感謝您的答覆...但我已經從打開的數據庫有我的數據。看到上面的編輯..也許它會幫助你更好地理解我的問題。 – Sumitha