2015-09-06 82 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放到了成功的位置。 非常感謝您的幫助。