【发布时间】:2019-06-10 09:18:04
【问题描述】:
我正在为大数据创建一个旭日形。为了使其更具可读性,我需要为每个节点分配不同的颜色(理想情况下,每个子树具有相同颜色的不同深浅)。
我已经尝试过:
d3.scaleSequential()
d3.scale.ordinal()
d3.scale.category20c()
我认为它可以工作,但我不知道该放在哪里。目前它只对每个子树使用一种颜色。
var width = 500;
var height = 500;
var radius = Math.min(width, height) / 2;
var color = d3.scaleSequential().domain([1,10]).interpolator(d3.interpolateViridis);
var g = d3.select('svg')
.attr('width', width)
.attr('height', height)
.append('g')
.attr('transform', 'translate(' + width / 2 + ',' + height / 2 + ')');
var partition = d3.partition() //.layout
.size([2 * Math.PI, radius]);
d3.json("file:///c:\\Users\\c1972519\\Desktop\\Stage\\tests_diagrams\\figure_4.8_ex3\\data2.json", function(error, nodeData){
if (error) throw error;
var root = d3.hierarchy(nodeData)
.sum(function(d){
return d.size;
});
partition(root);
var arc = d3.arc()
.startAngle(function(d) { return d.x0; })
.endAngle(function(d) { return d.x1; })
.innerRadius(function(d) { return d.y0; })
.outerRadius(function(d) { return d.y1; });
var arcs = g.selectAll('g')
.data(root.descendants())
.enter()
.append('g')
.attr("class", "node")
.append('path')
.attr("display", function (d) { return d.depth ? null : "none"; })
.attr("d", arc)
.style('stroke', '#fff')
.style("fill", function(d){return color(d)});
}
所以我想在每个子树上使用不同的阴影以使其更具可读性。
有人有想法吗?
【问题讨论】:
标签: javascript d3.js colors sunburst-diagram