0

I am working on the example of scatter plot from NVD3: http://nvd3.org/examples/scatter.html

As you can see in this example, in Legend, word "Group" gets mentioned repetitively for every series. Is it possible to write the word "Group" before the legend starts and then each of the series just show numbers "1", "2", "3" and so on?

Thanks !!

PS1
  • 179
  • 1
  • 1
  • 7
  • Try changing the `Key` value in your data. – shabeer90 Jul 02 '14 at 10:17
  • @shabeer90 That doesn't solve my problem. If I change the Key value, it will still appear after the series round circle. Say, I made the first series key as "Group 1" and series following that as "2", "3" then it will appear like that. I want the word "Group" to appear before the first round circle. – PS1 Jul 02 '14 at 10:20
  • Have a look at [this](http://stackoverflow.com/questions/16459585/how-to-a-title-for-a-nvd3-js-graph) – shabeer90 Jul 02 '14 at 10:57
  • @shabeer90 that indeed is a great solution. Works well, however this solution has two side effects: I am calling my generate_chart() function with different data. So, I need to be able to adjust the x-position-value relative to the legend position and I dont know that x-position-value beforehand. It would be great if I can add it relative to the legend. I tried appending to ".nv-legendWrap" but even that is not relative. Second side effect, the new labels are getting written over one another. How do I clear the earlier label on every initiation of the chart? – PS1 Jul 02 '14 at 11:48
  • Can you put you code on a [fiddle](http://jsfiddle.net/) so some one could have a look at the code and help you out. – shabeer90 Jul 02 '14 at 12:06

1 Answers1

0

You can use chart.legend.key() (source code):

chart.legend.key(function(d){return "Group "+d.key})

If the key attribute is 0 instead of Group 0, you will have what you want.

Christopher Chiche
  • 15,075
  • 9
  • 59
  • 98