无法将变量或动态数据分配给 angularjs 中的融合图表
unable to assign variable or dynamic data to fusion charts in angularjs
我想加载动态数据并显示柱面图。静态值图表工作但可变数据无法分配给融合图表的值字段。
http://jsfiddle.net/qe5ruLqz/8/
<td >
<fusioncharts id="chartContainer1" width="371" height="400" type="cylinder" datasource={{Bin1Data}}></fusioncharts>
</td>
<script>
var app = angular.module('myApp', ["ng-fusioncharts"]);
app.controller('myCtrl', function ($scope, $http) {
$http.get('https://example.com', {
headers: { 'Authorization': 'Basic abcd==' }
})
.then(function (response) {
$scope.names = response.data;
$scope.decodedFrame = atob($scope.names.dataFrame);
$scope.decodedFrameNew = $scope.decodedFrame.substring(4);
$scope.distanceinFeet = $scope.decodedFrameNew * 12.5 * 2.54;
$scope.Value = $scope.distanceinFeet / 148;
$scope.bin1Value = $scope.Value.toFixed(2);
$scope.names.timestamp = new Date($scope.names.timestamp).toLocaleString(); // Parse the date to a localized string
$scope.Bin1Data.chart.value[0].value = $scope.bin1Value;// assigning value to chart
});
$scope.Bin1Data = {
"chart": {
"caption": "Tank 2",
"lowerLimit": "0",
"upperLimit": "100",
"showValue": "1",
"valueBelowPivot": "1",
"theme": "fint",
"width": '50%',
"height": '50%',
"value": [{
"value": 0 //unble to assign values here
}]
}
};
});
您提供的问题代码与 fiddle 不同。 我的回答是基于fiddle!
您的分配不正确。您应该将数据传递给 $scope.Bin1Data.chart.value
.
我编辑了您的 fiddle 以传递动态数据。寻找刷新功能和按钮。我认为这是个好主意:
我想加载动态数据并显示柱面图。静态值图表工作但可变数据无法分配给融合图表的值字段。
http://jsfiddle.net/qe5ruLqz/8/
<td >
<fusioncharts id="chartContainer1" width="371" height="400" type="cylinder" datasource={{Bin1Data}}></fusioncharts>
</td>
<script>
var app = angular.module('myApp', ["ng-fusioncharts"]);
app.controller('myCtrl', function ($scope, $http) {
$http.get('https://example.com', {
headers: { 'Authorization': 'Basic abcd==' }
})
.then(function (response) {
$scope.names = response.data;
$scope.decodedFrame = atob($scope.names.dataFrame);
$scope.decodedFrameNew = $scope.decodedFrame.substring(4);
$scope.distanceinFeet = $scope.decodedFrameNew * 12.5 * 2.54;
$scope.Value = $scope.distanceinFeet / 148;
$scope.bin1Value = $scope.Value.toFixed(2);
$scope.names.timestamp = new Date($scope.names.timestamp).toLocaleString(); // Parse the date to a localized string
$scope.Bin1Data.chart.value[0].value = $scope.bin1Value;// assigning value to chart
});
$scope.Bin1Data = {
"chart": {
"caption": "Tank 2",
"lowerLimit": "0",
"upperLimit": "100",
"showValue": "1",
"valueBelowPivot": "1",
"theme": "fint",
"width": '50%',
"height": '50%',
"value": [{
"value": 0 //unble to assign values here
}]
}
};
});
您提供的问题代码与 fiddle 不同。 我的回答是基于fiddle!
您的分配不正确。您应该将数据传递给 $scope.Bin1Data.chart.value
.
我编辑了您的 fiddle 以传递动态数据。寻找刷新功能和按钮。我认为这是个好主意: