1

I have a jsD3 area graphic, data contains daily values of some metric, for many days I have the same values, so my graph have peaks at certain points when the values goes up or down, and horizontal line for the dates the value is the same. How to highlight with circles only the "peaks" (when data is different from previous days, increase or decrease)?

If I render circles for same data, they repeat one close to the other for the dates with same values.

For example consider this sample: http://bl.ocks.org/mbostock/3883195 but using this data:

date    close
14-May-14   10
15-May-14   10
16-May-14   12
17-May-14   12
18-May-14   10
19-May-14   10
20-May-14   10
21-May-14   10
22-May-14   28
24-May-14   39
25-May-14   39
26-May-14   49
27-May-14   49
28-May-14   59
28-May-14   48
30-May-14   49

This is the rendered chart: enter image description here

I would like to get highlight the value changes only so the resulting chart is like this: enter image description here

edteke
  • 562
  • 5
  • 22
  • There are a number of ways to achieve this, somehow you need to dynamically class your points, say perhaps a mathematical relationship that changes for a change from one data point to the next and call this class highlight and everything else normal. Then you could simply use a scatter plot to place the points styling them with css (normal opacity 0 and highlight opacity 1). – user1614080 May 22 '14 at 22:01

1 Answers1

0

This is pretty late I guess but I've recently been doing research into similar things:

d3.select('#chart1 svg').selectAll("circle.nv-point")        
   .data(testdata[0].values)                                                                 
.filter(function(d) {return d.y > 20000; })
    .style("fill-opacity",1);

The above is what I've been using so far, it highlights all the points whose values are greater than 20000 (of course this would be different for yours) and makes the points visible.

Hopefully this helps some, I'm new to d3 and have been trying to find answers to a similar problem as yours.

spaghetti
  • 1
  • 1
  • Yes, is different indeed, thanks for the answer anyway. I'm looking for the ability to display the points that are different from the previous one, not from a certain fixed (or variable) values, the criteria is the previous or next points, whether they are different or not. – edteke Jul 23 '14 at 22:31
  • Oh interesting, I must've misunderstood. If you keep a global variable and use the inner function to keep checking back to that, would that not work? You could keep track of the previous value and know when it's changed – spaghetti Jul 24 '14 at 12:09