代码之家  ›  专栏  ›  技术社区  ›  Kenny Nguyen

nvd3烛台图表不显示自定义数据

  •  0
  • Kenny Nguyen  · 技术社区  · 7 年前

    我有一个nvd3角度烛台图表,显示硬编码的数据刚刚好。但是当我把它指向另一个数据源(socket.io)时,它就不再显示了。

     $scope.getdata = function () {
        console.log("getting data!");
        io.socket.get('/feed/getpolodata', function (data, jwr, err) {
            var values = [];
            angular.forEach(data.candleInfo, function (r) {
                //$scope.data
                values.push({
    
                    "date": r.date,
                    "close": r.close,
                    "open": r.open,
                    "high": r.high,
                    "low": r.low,
                    "volume": r.volume,
                    "adjusted": r.low
    
                });
    
                if (err) {
                    console.log("Error getting data")
                }
            });
    
            $scope.data.push({values});
    
            console.log("js" + JSON.stringify($scope.data));
            console.log("js2" + JSON.stringify($scope.data2));
        })
    };
    

    $范围。数据包含自定义数据和$scope。数据包含用于测试的硬编码数据。

    数据2:

        $scope.data2 = [{
        values: [
            { "date": 1499031328, "close": 0.00008231, "open": 0.0000816, "high": 0.00008267, "low": 0.0000816, "volume": 12.09695909596307, "adjusted": 0.0000816 },
            { "date": 1499031388, "close": 0.00008303, "open": 0.000083, "high": 0.0000837, "low": 0.00008294, "volume": 10.91308942290992, "adjusted": 0.00008294 }
        ]
    }]
    

    当我将图形的数据值指向data2时,它工作得很好。但是,当我指向$scope.data时,什么也不显示。

    编辑:这是console.log的结果

    js[{"values":[{"date":1499034558,"close":0.00008388,"open":0.0000848,"high":0.0000848,"low":0.00008388,"volume":0.8672647004639618,"adjusted":0.00008388},{"date":1499034618,"close":0.00008405,"open":0.00008388,"high":0.00008574,"low":0.00008388,"volume":16.091108890994363,"adjusted":0.00008388},{"date":1499034678,"close":0.0000843,"open":0.00008405,"high":0.00008574,"low":0.00008388,"volume":2.3125435626714554,"adjusted":0.00008388},{"date":1499034738,"close":0.0000845,"open":0.0000843,"high":0.00008574,"low":0.00008388,"volume":0.012429811837685201,"adjusted":0.00008388}]}]
    js2[{"values":[{"date":1499031328,"close":0.00008231,"open":0.0000816,"high":0.00008267,"low":0.0000816,"volume":12.09695909596307,"adjusted":0.0000816},{"date":1499031388,"close":0.00008303,"open":0.000083,"high":0.0000837,"low":0.00008294,"volume":10.91308942290992,"adjusted":0.00008294}]}]
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Kenny Nguyen    7 年前

    通过添加

            $scope.$apply();
            $scope.api.refresh();
    

    工作完美