dimple tickFormat忽略分组逗号

时间:2016-09-23 10:05:51

标签: javascript d3.js dimple.js

我有一个显示一些大数字的凹坑图。我希望精确值出现在工具箱中(不会截断为14k),因此我更改了tickFormat。但是,dimple / d3似乎忽略了分组逗号,这使得大数字难以处理。

// this prints "12,345" as expected
var f = d3.format(",.0f");
console.log(f(12345.123));

var data = [{"date":"2016-01-18","completed":1234123.100},{"date":"2016-01-19","completed":1345123.0},{"date":"2016-01-20","completed":2123123.1}]

var svg = dimple.newSvg("#foo", "100%", "100%");
var myChart = new dimple.chart(svg, data);
var x = myChart.addTimeAxis("x", "date", "%Y-%m-%d", "%d/%m");
var y = myChart.addMeasureAxis("y", "completed");

// this does not work
// tooltips and y axis values appear without grouping comma
y.tickFormat = d3.format(",.0f");
myChart.setMargins("60px", "30px", "30px", "70px");
series = myChart.addSeries(null, dimple.plot.line);
myChart.draw();

1 个答案:

答案 0 :(得分:1)

根据API文档,属性dimple.axis.tickFormat将接受格式说明符字符串(即",.0f")。因为它被传递给d3.format()。您不必亲自致电d3.format();这是在函数_getFormat()内部完成的。因此,您的代码变为

y.tickFormat = ",.0f";