0

I am using nvd3 line chart and I would like that points under certain y value (let's say y=4) will be red, and above that they will be their nvd3 color (orange, etc..)

How can I achieve this kind of effect?

Yosi
  • 2,936
  • 7
  • 39
  • 64

1 Answers1

3

This can be done by adding a color value to the points of the linechart data.

Therefore, instead of having just x and y objects:

{...{"y": "0.05885", "x": "1692"}, {"y": "0.05906", "x": "1693"}...}

You have to add a color value:

{...{"y": "0.05885", "x": "1692", "color": "#ff0000"}, 
{"y": "0.05906", "x": "1693","color": "#ff0000"}...}.

This can then be accessed and changed as you normally would. For the required data points, you can make the color e.g. red as needed.

EDIT:

If that doesn't work, i don't think its possible, nicely. The problem is, is that the line itself is a actual line and its one element. If you look into the generated html code, you will see its a single element. Therefore, the line can only have a single colour property. What you can do is set that to a gradient link. Making the colour property be e.g.stroke: linear-gradient(to right, red , blue);, ofcourse with stops and starts when needed, look at this: link.

The way you access the line element is in css:

#graphid g.nv-series-0 path.nv-line { //0 is the series number
     #color:red; //old
     stroke: linear-gradient(to right, red , blue); //new
}
Community
  • 1
  • 1
Luka Prelic
  • 181
  • 2
  • 12
  • I tried to do this - https://gist.github.com/yosiat/59245d2866685780f87d#file-line-html-L84 and it draw a blue line for me, instead of partial red and partial black. – Yosi Apr 19 '15 at 17:39