我正在構建一個散點圖 https://codepen.io/DeanWinchester88/pen/QWgGMja
我無法使Y軸顯示為xx : xx<的格式,但我不明白為什么X軸要這樣顯示年份。請幫助我
https://codepen.io/freeCodeCamp/pen/bgpXyK - 這就是它的外觀
const xScale = d3.scaleLinear()
.domain([ d3.min(year), d3.max(year)] )
.range([paddings.paddingLeft,w - paddings.paddingRight] )。)
const xAxis = d3.axisBottom(xScale)。
svg.append("g"/span>)
.attr("transform", "translate(0," (h - paddings.paddingLeft) " )")
.attr("id","X-axis")
.call(xAxis)。
uj5u.com熱心網友回復:
要做到這一點,你需要使用tickformat函式
像這樣:var xAxis = d3.axisBottom(xScale).tickFormat(d3.format('d'));
在這里,它被放置在你給定的代碼片斷中:
。 const xScale = d3.scaleLinear()
.domain([ d3.min(year), d3.max(year)] )
.range([paddings.paddingLeft,w - paddings.paddingRight] )。)
var xAxis = d3.axisBottom(xScale)。 tickFormat(d3.format('d'))。
svg.append("g")
.attr("transform", "translate(0," (h - paddings.paddingLeft) " )")
.attr("id","X-axis")
.call(xAxis);
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
這應該可以解決您的問題,即在X軸上不能按預期顯示茶葉的年份。
這里有一個關于 tickformat 的進一步資訊的鏈接。https://github.com/d3/d3-axis
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/320652.html
標籤:
下一篇:jsd3圖表的時間刻度
