2015-09-06 32 views
-3

我得到一些图表的数据,我需要它们的最大值。 在我的成功,我正确得到$ scope.tempData中的这个值,但我怎么能在$ scope.options scaleStepWidth中使用它?如何使用http.post角度请求中的“data”取消成功?

这里是我的代码

$scope.truc = []; 
    $scope.tac = []; 
    $scope.tic; 
    $scope.tempData = 0; 
    $scope.chargerStats = function() { 

     var idProd = document.getElementById("idProduit").value; 

     $http.post("{{path('pfcrm_phone_factory_graphe_nbventesproduitpartemps')}}", {id: idProd}) 
       .success(function (data, status, headers, config) { 
        $scope.data = data; 
        $scope.truc = $scope.data['datasets']; 
        $scope.tac = $scope.truc[0].data; 

        $scope.tempData = Math.max.apply(null, $scope.tac); 

       }) 
       .error(function (data, status, headers, config) { 

        alert("Erreur pour l'affichage des graphiques"); 
       }); 

    }; 


    var steps = 3; 
    // Chart.js Options 
    $scope.options = { 
     // Sets the chart to be responsive 
     responsive: true, 
     // Boolean - If we should show the scale at all 
     showScale: true, 
     // Boolean - If we want to override with a hard coded scale 
     scaleOverride: true, 
     // Number - The number of steps in a hard coded scale 
     scaleSteps: steps, 
     // Number - The value jump in the hard coded scale 
     scaleStepWidth: 500, 
     //Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value 
     scaleBeginAtZero: true, 
     //Boolean - Whether grid lines are shown across the chart 
     scaleShowGridLines: true, 
     //String - Colour of the grid lines 
     scaleGridLineColor: "rgba(0,0,0,.05)", 
     //Number - Width of the grid lines 
     scaleGridLineWidth: 1, 
     //Boolean - If there is a stroke on each bar 
     barShowStroke: true, 
     //Number - Pixel width of the bar stroke 
     barStrokeWidth: 2, 
     //Number - Spacing between each of the X value sets 
     barValueSpacing: 5, 
     //Number - Spacing between data sets within X values 
     barDatasetSpacing: 1 
    }; 
}); 

非常感谢。

+0

你的意思是提取?你想显示在HTML? –

+0

不需要'{{}}'内部控制器使用'$ scope.variableName'这就是我的猜想..你到底想要什么? –

+0

对不起,我是初学者^^,我的请求正在工作,如果我“console.log”我的$ score.tempData在成功,它返回了良好的价值,但出于成功,我无法得到它。我不明白为什么。 –

回答

0

我解决了我的问题,把我的$ scope.option放到了成功的位置。 非常感谢您的帮助。