我找到了看起来非常好且友好的图书馆nvD3-Angular。 我用它来绘制静态数据,但我希望能够读取存储在我的数据库中的数据。有没有办法使用JQuery通过AJAX使用提到的数据设置数据变量? 我知道必须有一种方法来获取这些数据,我还没有发现它。
我的代码如下: 在我的HTML中:
<div ng-controller="PlotController">
<nvd3 options="options" data="data">
</nvd3>
</div>
在控制器中:
app.controller('PlotController', function($scope){
/* Chart options */
$scope.options = {
chart: {
type: 'cumulativeLineChart',
height: 450,
margin : {
...
},
}
};
$scope.initData = [
{
key: "Cis ON",
mean: 250,
values: [ [ 1083297600000 , -2.974623048543] , ... , [ 1354251600000 , 349.45128876100]]
},
{
key: "Cis OFF",
mean: -60,
values: [ [ 1083297600000 , -0.77078283705125] ,..., [ 1085976000000 , -1.8356366650335]]
},
];
//Chart data
$scope.data = angular.copy($scope.initData);
});
作为额外信息: 服务器端使用Php Laravel 5.1进行编码,使用mysql作为数据库。
感谢任何指导。
答案 0 :(得分:0)
在此处参考angularjs中的$http
服务:https://docs.angularjs.org/api/ng/service/ $ http
样品:
$http({
method: 'GET',
url: 'your api url'
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
}).catch(function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});