[英]D3 Line chart - display value label on Y axis tick and a not scale
我想在Y軸上打印標簽,而不是刻度刻度范圍。 這是我的數據集,我希望在其中在Y軸上打印data.values [i] .label。
var data = [
{
name: "USA",
values: [
{date: "2000", price: "500", label: "High"},
{date: "2001", price: "400", label: "High"},
{date: "2002", price: "300", label: "Medium"},
{date: "2003", price: "200", label: "Medium"},
{date: "2004", price: "100", label: "Low"},
{date: "2005", price: "200", label: "Medium"}
]
}
];
我以為我需要在157行做點什么,就像在這里回答的那樣,但是我需要傳遞值[i],而不僅僅是價格。 就像是
var yAxis = d3.axisLeft(yScale).tickFormat( function(d) { return d.label } );
希望對您有幫助
var yAxis = d3.axisLeft(yScale).ticks(5).tickFormat( function(d, i) { return data[0].values[i].label; } );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.