在 dc.js / d3 图表中格式化 y 轴上的值
Formatting values on the y axis in a dc.js / d3 chart
我正在尝试缩短 Y 轴上的值,目前它们是这样显示的:
虽然我可以使用填充,但我希望 Y 轴以这种方式显示:
100,000 = 100k
200,000 = 200k
等等等等
附上我的代码。
var paidSubChart = dc.lineChart("chart1")
.width(450)
.height(300)
.elasticX(true)
.x(d3.scale.linear().domain([-30,N]))
.elasticY(true)
.brushOn(false)
.yAxisLabel("Paid Subs")
.xAxisLabel("Days Since Launch")
.dimension(dayCountDimension)
.group(paidSubGroup);
var expansionActChart = dc.lineChart("chart2")
.width(450)
.height(300)
.elasticX(true)
.x(d3.scale.linear().domain([0,N]))
.elasticY(true)
.brushOn(false)
.yAxisLabel("Paid Subs")
.xAxisLabel("Days Since Launch")
.dimension(dayCountDimension)
.group(expActGroup);
dc.js中的轴由d3.js提供。
我想你正在寻找
chart.yAxis().tickFormat(d3.format('.3s'))
调用 d3.axis.tickFormat and uses d3.format 的 "SI prefix"。
注意:最好将轴操作放在单独的语句中,因为 stuff breaks if you try to chain other dc.js chart commands after a yAxis
command。
我正在尝试缩短 Y 轴上的值,目前它们是这样显示的:
虽然我可以使用填充,但我希望 Y 轴以这种方式显示:
100,000 = 100k
200,000 = 200k
等等等等
附上我的代码。
var paidSubChart = dc.lineChart("chart1")
.width(450)
.height(300)
.elasticX(true)
.x(d3.scale.linear().domain([-30,N]))
.elasticY(true)
.brushOn(false)
.yAxisLabel("Paid Subs")
.xAxisLabel("Days Since Launch")
.dimension(dayCountDimension)
.group(paidSubGroup);
var expansionActChart = dc.lineChart("chart2")
.width(450)
.height(300)
.elasticX(true)
.x(d3.scale.linear().domain([0,N]))
.elasticY(true)
.brushOn(false)
.yAxisLabel("Paid Subs")
.xAxisLabel("Days Since Launch")
.dimension(dayCountDimension)
.group(expActGroup);
dc.js中的轴由d3.js提供。
我想你正在寻找
chart.yAxis().tickFormat(d3.format('.3s'))
调用 d3.axis.tickFormat and uses d3.format 的 "SI prefix"。
注意:最好将轴操作放在单独的语句中,因为 stuff breaks if you try to chain other dc.js chart commands after a yAxis
command。