[英]D3 Line chart - display value label on Y axis tick and a not scale
I'd like to print a label on the Y axis instead of a scaled tick range. 我想在Y轴上打印标签,而不是刻度刻度范围。 Here is my dataset, where I want wish to print data.values[i].label on the Y axis. 这是我的数据集,我希望在其中在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"}
]
}
];
I figured I need to do something on line 157 like was answered here but I would need to pass the values[i] in, and not just the price. 我以为我需要在157行做点什么,就像在这里回答的那样,但是我需要传递值[i],而不仅仅是价格。 Something like 就像是
var yAxis = d3.axisLeft(yScale).tickFormat( function(d) { return d.label } );
Some guidance would be appreciated. 一些指导将不胜感激。 I've been testing it on codepen here 我在这里在Codepen上测试过
希望对您有帮助
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.