| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <html>
- <head>
- <title>Stacked Area Chart</title>
- <script type="text/javascript" src="../protovis-d3.1.js"></script>
- </head>
- <body>
- <script type="text/javascript+protovis">
- var data = pv.range(4).map(function()
- pv.range(0, 10, .1).map(function(x) {
- return {x: x, y: Math.sin(x) + Math.random() * .5 + 2};
- })),
- w = 400,
- h = 200,
- x = pv.Scale.linear(0, 9.9).range(0, w),
- y = pv.Scale.linear(0, 14).range(0, h);
- var vis = new pv.Panel()
- .width(w)
- .height(h)
- .bottom(20)
- .left(20)
- .right(10)
- .top(5)
- .strokeStyle("#ccc");
- vis.add(pv.Panel)
- .data(data)
- .add(pv.Area)
- .data(function(a) a)
- .left(function(d) x(d.x))
- .bottom(pv.Layout.stack())
- .height(function(d) y(d.y));
- vis.add(pv.Rule)
- .data(x.ticks())
- .visible(function(d) d > 0)
- .left(function(d) Math.round(x(d)) - .5)
- .strokeStyle("rgba(128,128,128,.1)")
- .anchor("bottom").add(pv.Label)
- .text(function(d) d.toFixed());
- vis.add(pv.Rule)
- .data(y.ticks())
- .visible(function() !(this.index % 2))
- .bottom(function(d) Math.round(y(d)) - .5)
- .strokeStyle("rgba(128,128,128,.2)")
- .anchor("left").add(pv.Label)
- .text(function(d) d.toFixed());
- vis.render();
- </script>
- </body>
- </html>
|