Skip to content

Commit 31a7273

Browse files
committed
Add Sankey and Stream Graph examples
1 parent 15d7a36 commit 31a7273

File tree

13 files changed

+2851
-1
lines changed

13 files changed

+2851
-1
lines changed

examples/Sankey/App.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from 'react';
2+
import Highcharts from 'highcharts';
3+
import {
4+
HighchartsChart, withHighcharts, XAxis, YAxis, Title, SankeySeries, Tooltip
5+
} from 'react-jsx-highcharts';
6+
import ExampleCode from '../utils/ExampleCode';
7+
import code from './exampleCode';
8+
9+
const data = {
10+
Brazil: { Portugal: 5, France: 1, Spain: 1, England: 1 },
11+
Canada: { Portugal: 1, France: 5, England: 1 },
12+
Mexico: { Portugal: 1, France: 1, Spain: 5, England: 1 },
13+
USA: { Portugal: 1, France: 1, Spain: 1, England: 5 },
14+
Portugal: { Angola: 2, Senegal: 1, Morocco: 1, 'South Africa': 3 },
15+
France: { Angola: 1, Senegal: 3, Mali: 3, Morocco: 3, 'South Africa': 1 },
16+
Spain: { Senegal: 1, Morocco: 3, 'South Africa': 1 },
17+
England: { Angola: 1, Senegal: 1, Morocco: 2, 'South Africa': 7 },
18+
'South Africa': { China: 5, India: 1, Japan: 3 },
19+
Angola: { China: 5, India: 1, Japan: 3 },
20+
Senegal: { China: 5, India: 1, Japan: 3 },
21+
Mali: { China: 5, India: 1, Japan: 3 },
22+
Morocco: { China: 5, India: 1, Japan: 3 }
23+
};
24+
25+
const App = () => {
26+
const formattedData = Object.keys(data).reduce((arr, from) => {
27+
const weights = data[from];
28+
return arr.concat(Object.keys(weights).map(to => [from, to, weights[to]]));
29+
}, []);
30+
31+
return (
32+
<div className="app">
33+
<HighchartsChart>
34+
<Title>Highcharts Sankey Diagram</Title>
35+
36+
<XAxis type="category" />
37+
38+
<YAxis id="y">
39+
<SankeySeries id="sankey" name="Sankey demo series" data={formattedData} keys={['from', 'to', 'weight']} />
40+
</YAxis>
41+
42+
<Tooltip />
43+
</HighchartsChart>
44+
45+
<ExampleCode name="Sankey">{code}</ExampleCode>
46+
</div>
47+
);
48+
}
49+
50+
export default withHighcharts(App, Highcharts);

0 commit comments

Comments
 (0)