Angularjs angular nvd3 xAxisTickFormatFunction更新我不想要的数据
在角度nvd3中使用了两个函数。它们是xAxisTickFormatFunction和toolTipContentFunctionAngularjs angular nvd3 xAxisTickFormatFunction更新我不想要的数据,angularjs,d3.js,nvd3.js,Angularjs,D3.js,Nvd3.js,在角度nvd3中使用了两个函数。它们是xAxisTickFormatFunction和toolTipContentFunction $scope.xAxisTickFormatFunction = function() { return function(d) { return d3.time.format("%b, %Y")(new Date(d)); }; } $scope.toolTipContentFunction = functio
$scope.xAxisTickFormatFunction = function() {
return function(d) {
return d3.time.format("%b, %Y")(new Date(d));
};
}
$scope.toolTipContentFunction = function() {
return function(d) {
return d3.time.format("%Y-%m-%d")(new Date(d));
}
}
两个函数中的哪个d表示相同的值。d的原始值是日期类型,如2014-06-20,但在xAxisTickFormatFunction中使用后,结果是2014年6月,然后在toolTipContentFunction中,它的值将显示为2014-06-01,而不是2014-06-20,这意味着由于使用了格式,数据丢失。
如何避免数据被更新?我发现,虽然d的值已更改,但我们可以从参数x访问d属性,而属性d的值尚未更新
$scope.toolTipContentFunction = function() {
return function(d, x) {
return d3.time.format("%Y-%m-%d")(new Date(x.point.d));
}
}
以下是如何在示例中的angular nvd3指令中使用toolTipContentFunction的示例代码
$scope.toolTipContentFunction = function(){
return function(key, x, y, e, graph) {
return 'Super New Tooltip' +
'<h1>' + key + '</h1>' +
'<p>' + y + ' at ' + x + '</p>'
}
}