Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Adding labels and legends to the charts dynamically #9

Open
dynamicishwar opened this issue Aug 14, 2013 · 2 comments
Open

Adding labels and legends to the charts dynamically #9

dynamicishwar opened this issue Aug 14, 2013 · 2 comments

Comments

@dynamicishwar
Copy link

I have started using the code here for an application which will go live in a few months time.
Currently the charts only allow captions but does not allow labels and legends. Can we have this feature set added to the same or if you could suggest a workaround.....

@drsm79
Copy link
Owner

drsm79 commented Aug 16, 2013

I think the right thing to do here is to add the legend/label directly (http://bl.ocks.org/ZJONSSON/3918369 for an example). You don't really need to wire them up to the backbone MVC stuff, unless you're planning for them to be data driven.

You might want to look at rickshaw or nvd3 - both are much better in terms of feature set and are easily integrated with Backbone (which is why this project hasn't seen much in the way of updates recently)

@dynamicishwar
Copy link
Author

Thanks Simon. The labels need to be data driven. Currently successful in rendering captions in the following manner (for bar charts)
chart.selectAll("rect")
.data(data)
.enter().append("svg:rect")
.attr("x", function(d, i) { return x(i) - .5; })
.attr("y", function(d) { return yval(d) })
.attr("width", w)
.append("svg:title")
.text(function(d) {
return d.x;
})
.attr("height",
function(d) { return scale * d.y; });
I do not want to hard code the text in the bar.js nor would like to send an additional attribute to the Javascript. Adding something in this fashion works... but is not what is needed...
chart.append("text")
.attr("class", "y label")
.attr("text-anchor", "end")
.attr("y", 6)
.attr("dy", ".75em")
.attr("transform", "rotate(-90)")
.text("Test Y Axis");

Is there an alternative route to rendering labels inside the bar.js ......

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants