gpt4 book ai didi

svg - NVD3.js 为图表中的特定条形着色

转载 作者:行者123 更新时间:2023-12-04 00:43:26 26 4
gpt4 key购买 nike

有没有办法给特定的条上色?如果条小于线,则将其涂成红色。

代码:https://github.com/tvinci/webs/blob/gh-pages/lineplusbar.html

示例:http://tvinci.github.io/webs/lineplusbar.html

我想做这样的事情,但 i 的值不是我发送的 y 值。它已被修改:

d3.selectAll("rect.nv-bar")
.style("fill", function(d, i){
return i > 50 ? "red":"blue";
});

数据:

var overview_data=[
{
"key" : "Achieved",
"bar": true,
"values" : [ [ "1x" , 30] , [ "2x" , 70] , [ "3x" , 200] ]
},
{
"key" : "Required",
"values" : [ [ "1x" , 50] , [ "2x" , 100] , [ "3x" , 150] ]
}
].map(function(series) {
series.values = series.values.map(function(d) { return {x: d[0], y: d[1] } });
return series;
});

最佳答案

你可以这样做:

d3.selectAll("rect.nv-bar")
.style("fill", function(d, i){
return d.y > 50 ? "red":"blue";
});

关于svg - NVD3.js 为图表中的特定条形着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15947967/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com