使用y的字符串值角+ D3 tickFormat [英] angular + d3 tickFormat using a string value for y
问题描述
我有如下图配置:
nv.addGraph(function() {
var chart = nv.models.cumulativeLineChart()
.x(function(d) { return d.x.getTime() })
.y(function(d) { return d.y })
.color(d3.scale.category10().range());
chart.xAxis
.axisLabel('Período')
.tickFormat(function(d) {
return d3.time.format("%m/%y")(new Date(d));
});
chart.yAxis
.axisLabel('Rentabilidade')
.tickFormat(function(d) {
return (d * 100).toFixed(2) + '%';
});
d3.select('#profitability-chart')
.datum(data)
.transition().duration(500)
.call(chart);
return chart;
});
问题是,在每一个图表的最后一点显示了不同格式是
值。例如:
行富上图:
- 最后一点显示为36%
- 检查的
数据
阵列,
- Y = 1.7205607426554128
- display.y = 0.3602803713277064
这里的数据样本。
我不知道这个的 display.y 的来源,而这个值是如何计算出来的。我以为
d3.format
正在发生变化的实际价值,所以我切换到手动tickFormat,但问题依然存在。I don't know where this display.y comes from, and how this value is computed. I thought
d3.format
was changing the real value, so I've switched to a manual tickFormat, but the problem still exists.PS:我还使用angular.js。
PS.: I'm also using angular.js.
推荐答案
拉尔斯Kotthoff 的回答评论。基本上,我建立我的数据是这样的:
Lars Kotthoff answered in a comment. Basically, I was build my data this way:
{ "key": "Fund 1", "values": [ { "x": "1999-11-05T02:00:00.000Z", "y": 1 }, { "x": "1999-11-13T02:00:00.000Z", "y": 1.00342088549313 }, ... ] }
基本上,我的
是
值分别为实际百分比,由第一值来计算分(这就是为什么第一个值是1)。Basically, my
y
values were actual percentages, calculated dividing by the first value (that's why the first value is 1).什么真正应该做的是图表给出绝对值,如:
What should really be done is give absolute values to the chart, like:
{ "key": "Fund 1", "values": [ { "x": "1999-11-05T02:00:00.000Z", "y": 120045.21 }, { "x": "1999-11-13T02:00:00.000Z", "y": 32521.01 }, ... ] }
和NVD3将计算所有的百分比。
And NVD3 will compute all percentages.
这篇关于使用y的字符串值角+ D3 tickFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!