我可以't用d3改变多线图中的线上的颜色
i can't change the colors on the lines in a multi line graph with d3
看起来我做的一切都很好,除了我不能改变颜色来区分行之外,这个代码应该可以工作:
colors = ["blue","red","yellow","green","black","blue","gray"];
linesGroup = svg.append("g").attr("class", "lines");
var linedata;
for (var i in chart_data) {
linedata = chart_data[i];
console.log(linedata);
linesGroup.append("path")
.attr("d", line(linedata.points))
.attr("class", "line")
.attr("fill", "none")
.attr("stroke", function(d, i) {
console.log(colors[Math.floor((Math.random()*6)+1)]);
return colors[colors[Math.floor((Math.random()*6)+1)]];
});;
};
我还在使用jsfiddle作为完整的示例http://jsfiddle.net/yr2Nw/
将笔划设置为内联样式,并正确访问颜色数组:
.style("stroke", function(d, i) {
return colors[Math.floor((Math.random()*6)+1)];
});
使用for in
循环并不是在d3中完成任务的一种非常习惯的方式(如果尝试使用i
,您会遇到问题)。
相关文章:
- 改变所有<td>为特定的桌子点击颜色
- 如何用jquery动画改变背景颜色,就像一个过渡
- 在用Javascript更改背景颜色后:hover don'不要改变颜色
- AJAX数据库更新与CSS按钮颜色改变使用Codeigniter
- & lt; meter>动画生命条颜色改变
- Javascript随机单元格背景颜色改变
- Jquery切换CSS颜色改变
- Jquery背景颜色改变按钮点击表内
- 每次球碰到墙时,将球的颜色改变为随机的颜色
- 谷歌地图路线方向路径颜色改变导航仪从一个航路点移动到另一个航路点
- Jquery鼠标悬停颜色改变
- Css下拉颜色改变器
- 根据底层颜色改变固定文本的颜色
- 文字的悬停颜色改变
- 谷歌地图API动画多边形颜色改变
- 改变字形点击+表头颜色改变
- jQuery动画颜色改变
- D3 javascript点击一条线来改变线的颜色-改变所有的线
- 如何使文字的颜色改变,当鼠标移动到图像上
- jQuery中的颜色/背景颜色改变动画