Skip to content

Commit cd3da28

Browse files
authored
Merge pull request #1094 from plotly/stacked-area-update
Stacked area update
2 parents b8977a4 + a3aca81 commit cd3da28

File tree

6 files changed

+254
-301
lines changed

6 files changed

+254
-301
lines changed

_posts/plotly_js/basic/area/2015-04-09-stacked-area.html

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,9 @@
99
---
1010
var plotDiv = document.getElementById('plot');
1111
var traces = [
12-
{x: [1,2,3], y: [2,1,4], fill: 'tozeroy'},
13-
{x: [1,2,3], y: [1,1,2], fill: 'tonexty'},
14-
{x: [1,2,3], y: [3,0,2], fill: 'tonexty'}
12+
{x: [1,2,3], y: [2,1,4], stackgroup: 'one'},
13+
{x: [1,2,3], y: [1,1,2], stackgroup: 'one'},
14+
{x: [1,2,3], y: [3,0,2], stackgroup: 'one'}
1515
];
1616

17-
function stackedArea(traces) {
18-
for(var i=1; i<traces.length; i++) {
19-
for(var j=0; j<(Math.min(traces[i]['y'].length, traces[i-1]['y'].length)); j++) {
20-
traces[i]['y'][j] += traces[i-1]['y'][j];
21-
}
22-
}
23-
return traces;
24-
}
25-
26-
Plotly.newPlot(plotDiv, stackedArea(traces), {title: 'stacked and filled line chart'});
17+
Plotly.newPlot(plotDiv, traces), {title: 'stacked and filled line chart'});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
name: Normalized Stacked Area Chart
3+
plot_url: https://codepen.io/plotly/embed/MqzvoO/?height=463&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: area
6+
order: 2.1
7+
sitemap: false
8+
arrangement: horizontal
9+
---
10+
var plotDiv = document.getElementById('plot');
11+
var traces = [
12+
{x: [1,2,3], y: [2,1,4], stackgroup: 'one', groupnorm:'percent'},
13+
{x: [1,2,3], y: [1,1,2], stackgroup: 'one'},
14+
{x: [1,2,3], y: [3,0,2], stackgroup: 'one'}
15+
];
16+
17+
Plotly.newPlot(stacksDiv, traces, {title: 'Normalized stacked and filled line chart'});
18+

0 commit comments

Comments
 (0)