2

Any idea of how I can make this dynamic line graph stacked? http://jsfiddle.net/praveen_jegan/QBDGB/6/

var options = {
    series: {
        stack: true,
        lines: {
            show: true,
            fill: true
        }
    },

Does any one have any example?

andyb
  • 43,435
  • 12
  • 121
  • 150
sasha
  • 179
  • 11
  • 1
    [This question](http://stackoverflow.com/questions/9664642/d3-real-time-streamgraph-graph-data-visualization) should help. – Lars Kotthoff Jul 05 '13 at 09:05
  • Rolled back to previous version. @sasha I'm not sure what you were trying to do but it was a very bad question edit. – andyb Jul 16 '13 at 16:14

2 Answers2

0

You could check the streamgraph example on d3js.org http://bl.ocks.org/mbostock/4060954

Barnabé Monnot
  • 1,163
  • 1
  • 9
  • 19
  • Thanks for your answer. I want to know if it is possible to make stacked graph while the graph is moving or not. I have not seen any example with dynamic graph while the x and y axis is moving. – sasha Jul 05 '13 at 09:00
  • An example of real time steam graph. http://lyngbaek.com/real-time-stream-graph.html – widged Jul 05 '13 at 15:21
0

All you need to do is to create a new data set that is a stacked version of your old data.

The following lines will do this for your example:

var data1s = data1;

var data2s = []; for(var i = 0; i < data1s.length; i++){data2s.push({time: data1[i].time, value:  data1s[i].value + data2[i].value}  )};

var data3s = []; for(var i = 0; i < data2s.length; i++){data3s.push({time: data2[i].time, value:  data2s[i].value + data3[i].value}  )};

var data4s = []; for(var i = 0; i < data3s.length; i++){data4s.push({time: data3[i].time, value:  data3s[i].value + data4[i].value}  )};

This is about the ugliest way you can create this data, but it works. I've created a fiddle of it here.

Note that, in making my fiddle work, I need to create this data initially, refer to this new stacked data in place of the original data, and also update the stacked data.

ckersch
  • 7,507
  • 2
  • 37
  • 44
  • Thank you so much for your answer :) it was nice. but it is still not stacked and I could not fill the area. stacking works fine with one serie, but for multiple series the colors crash :( – sasha Jul 08 '13 at 08:23
  • I'm not entirely sure what you mean. Is my example not the kind of 'stacked' that you're looking for, or are you still having problems with your code? – ckersch Jul 08 '13 at 20:29
  • Hello again :) sorry id I misunderstood you but by stacked I meant a filled graph. but your provided graph is not filled. – sasha Jul 09 '13 at 12:49