Prawidłowe użycie stack.values ([accessor]) w D3 Streamgraph?
Próbuję utworzyć wykres streamgraph D3 z dodatkowymi danymi na warstwę przy użyciu akcesora wartości, jak pokazano wD3 API odniesienia ito pytanie w Stack Overflow.
Tytuł dołącza się dobrze, ale nie wydaje się, aby dołączał wartości. Jakieś pomysły na to, co może pójść źle?
Jestem nowy w d3, więc jestem pewien, że to proste. Kod jest poniżej.
var layers = [
{
"name": "apples",
"values": [
{ "x": 0, "y": 91},
{ "x": 1, "y": 290}
]
},
{
"name": "oranges",
"values": [
{ "x": 0, "y": 9},
{ "x": 1, "y": 49}
]
}
];
var m = 2; // number of samples per layer
var width = 960,
height = 500,
mx = m - 1,
my = 350;
var stack = d3.layout.stack()
.offset("wiggle")
.values(function(d) { return d.values; });
var area = d3.svg.area()
.x(function(d) {
return d.x * width / mx;
})
.y0(function(d) {
return height - d.y0 * height / my;
})
.y1(function(d) {
return height - (d.y + d.y0) * height / my;
});
var vis = d3.select("#chart")
.append("svg")
.attr("width", width)
.attr("height", height);
vis.selectAll("path")
.data(stack(layers))
.enter().append("path")
.attr("d", area)
.append("title")
.text(function(d) { return d.name; });