javascript - Formatting Large Dollar Values with Single Data Point in D3 -
i have scatter plot filtering out data points based on user inputs. i'm using d3.format return x axis values dollars in following way:
var costformatter = d3.format('$' + 's'); xaxis = d3.svg.axis().orient('bottom').tickformat(function(d) { if (d === 0) { return 0; } else if (d < 0) { return ''; } else { return costformatter(d); } // returns $1.5m, 800k, etc. }); this works when have large number of points, when down single point on scatter plot, have 10 ticks return numbers $8.3498668m. i'd number appear $8.35m.
note: domain , range values dynamic, cannot explicitly set values with tickvalues()
unfortunately can't mix type g , type s in d3.format have this...
function f(x){ return d3.format('$,s')(x.toprecision(3)); } i did experimenting , s type seems include g behaviour it's easier...
d3.format('$,.3s') will give same result above function.
Comments
Post a Comment