簡體   English   中英

格式化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並使用d3.format的“ SI前綴”。

注意:最好將軸操作保留在單獨的語句中,因為如果嘗試在yAxis命令之后鏈接其他dc.js圖表​​命令,則內容會yAxis

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM