javascript - Accessing data in Tooltip on D3 Multi-line Chart -
javascript - Accessing data in Tooltip on D3 Multi-line Chart -
here data.
var info = [ { "label": "branch-1", "values": [ { "day": "monday", "value": 20}, { "day": "tuesday", "value": 18}, { "day": "wednesday", "value": 29}, { "day": "thursday", "value": 31}, { "day": "friday", "value": 37}, { "day": "saturday", "value": 25}, { "day": "sunday", "value": 19} ] }, { "label": "branch-2", "values": [ { "day": "monday", "value": 32}, { "day": "tuesday", "value": 29}, { "day": "wednesday", "value": 37}, { "day": "thursday", "value": 41}, { "day": "friday", "value": 31}, { "day": "saturday", "value": 28}, { "day": "sunday", "value": 17} ] } ]
i'm trying add together label tooltip, error "undefined". need append labels end of each line. similary, names in this example. can't find how accomplish this.
fiddle link code here.
to label in tooltip need have label name in individual info points:
modify info processing block follows:
data.foreach(function (kv) { var labelname = kv.label; kv.values.foreach(function (d) { d.value = +d.value; d.label = labelname; }); });
for adding labels add together next section:
city.append("text") .attr("transform", function(d) { var dayext = d.values[d.values.length - 1].day; var valueext = d.values[d.values.length - 1].value; homecoming "translate(" + x(dayext) + "," + y(valueext) + ")"; }) .attr("x", 3) .attr("dy", ".35em") .text(function(d) { homecoming d.label });
please find finish fiddle here: http://jsfiddle.net/prashant_11235/ly8zt/
you may style label names appropriately required.
javascript d3.js charts
Comments
Post a Comment