Javascript 在AngularJS中为图形创建对象数组

Javascript 在AngularJS中为图形创建对象数组,javascript,angularjs,Javascript,Angularjs,我正在使用n-3图表()在我的angular web应用程序中创建一些图形。以下是一些点的样本数据,其中有3个系列的数据值: $scope.data = [ {x: new Date(1391448620668), current: 0, baseline: 0, original: 0, val_3: 0}, {x: new Date(1391535020668), current: 0.993, baseline: 3.894, original: 8.47, val

我正在使用n-3图表()在我的angular web应用程序中创建一些图形。以下是一些点的样本数据,其中有3个系列的数据值:

$scope.data = [
      {x: new Date(1391448620668), current: 0, baseline: 0, original: 0, val_3: 0},
      {x: new Date(1391535020668), current: 0.993, baseline: 3.894, original: 8.47, val_3: 14.347},
      {x: new Date(1391621420668), current: 1.947, baseline: 7.174, original: 13.981, val_3: 19.991},
      {x: new Date(1391707820668), current: 2.823, baseline: 9.32, original: 14.608, val_3: 13.509},
      {x: new Date(1391794220668), current: 3.587, baseline: 9.996, original: 10.132, val_3: -1.167},
];
在我的代码中,我试图在相同的构造下创建它,如下所示:

$scope.addGraphData = function(){
  var firstSubDate  = $scope.FirstSubjectDoseDt;
  var xValues = new Array(); // date data points
  var cValues = new Array(); // current values
  var bValues = new Array(); // baseline values
  var oValues = new Array(); // original baseline values

  for (var i = 0; i < $scope.currentData.length; i++) {
    xValues[i] = new Date(firstSubDate+([i]*2628000000));
    cValues[i] = $scope.currentData[i].currentValue;
    bValues[i] = $scope.currentData[i].baselineValue;
    oValues[i] = $scope.currentData[i].origValue;
  };

  for (var i = 0; i < $scope.currentData.length; i++) {
    $scope.data[i] = {x: xValues[i], current: cValues[i], baseline: bValues[i], original: oValues[i]};
  };
  console.log("Graph Data: " + $scope.data);
};
$scope.addGraphData=function(){
var firstSubDate=$scope.FirstSubjectDoseDt;
var xValues=new Array();//日期数据点
var cValues=new Array();//当前值
var bValues=新数组();//基线值
var oValues=new Array();//原始基线值
对于(变量i=0;i<$scope.currentData.length;i++){
xValues[i]=新日期(firstSubDate+([i]*2628000000));
cValues[i]=$scope.currentData[i].currentValue;
bValues[i]=$scope.currentData[i].baselineValue;
oValues[i]=$scope.currentData[i].origValue;
};
对于(变量i=0;i<$scope.currentData.length;i++){
$scope.data[i]={x:xValues[i],current:cValues[i],baseline:bValues[i],original:oValues[i]};
};
log(“图形数据:+$scope.Data”);
};
但是$scope.data数组中的值存在,但是控制台给了我

图形数据:[对象对象],[对象对象],[对象对象对象]


对于我的3个数据点,它没有绘制任何内容。我哪里出错了?

问题是,如果其中一个值是
未定义的
,则图表无法调用数据集
$scope.data

例如:

$scope.data = [
      {x: new Date(1391448620668), current: undefined, baseline: 0, original: 0, val_3: 0},
      {x: new Date(1391535020668), current: 0.993, baseline: 3.894, original: 8.47, val_3: 14.347}
];
在创建
数据
数组时,我修改了函数以提高效率,并添加了OR条件,以便在未定义的情况下将值绘制为0。我还修复了一个约会错误

$scope.addGraphData = function(){
  var firstSubDate  = $scope.FirstSubjectDoseDt;

  $scope.data = [];

  console.log("firstSubDate:", firstSubDate);

  for (var i = 0; i < $scope.currentData.length; i++) {
    $scope.data[i] = {
      x: new Date( new Date(firstSubDate).getTime() + i*2628000000 ),
      current:  $scope.currentData[i].currentValue || 0,
      baseline: $scope.currentData[i].baselineValue || 0,
      original: $scope.currentData[i].origValue || 0
    };

  };

  console.log("Monthly Graph Data:", $scope.data);

};
$scope.addGraphData=function(){
var firstSubDate=$scope.FirstSubjectDoseDt;
$scope.data=[];
log(“firstSubDate:”,firstSubDate);
对于(变量i=0;i<$scope.currentData.length;i++){
$scope.data[i]={
新日期(新日期(firstSubDate).getTime()+i*2628000000),
当前:$scope.currentData[i].currentValue | | 0,
基线:$scope.currentData[i].baselineValue | | 0,
原始:$scope.currentData[i].origValue | | 0
};
};
log(“每月图形数据:”,$scope.Data);
};

您可以发布JSFIDLE或Plunker吗?您是如何填充这些数据的?它是否在AngularJS
$digest
循环中?@rtcherry它们由同一范围内的表单填充。我将尝试构建一个快速的JSFIDLE。我忘记了一些代码,更新了问题。
console.log(“图形数据:”,$scope.Data)
通常更有用