# Sankey Examples

**Component Reference:** Sankey or @splunk/visualizations/Sankey

## Basic Sankey

- **Key:** Basic

```jsx
import React from 'react';
import Sankey from '@splunk/visualizations/Sankey';

export default () => (
    <Sankey
        dataSources={{
            primary: {
                data: {
                    columns: [
                        ['Oil', 'Natural Gas', 'Coal', 'Coal', 'Fossil Fuels', 'Electricity'],
                        ['Fossil Fuels', 'Fossil Fuels', 'Fossil Fuels', 'Electricity', 'Energy', 'Energy'],
                        [15, 20, 25, 25, 60, 25],
                    ],
                    fields: ['source', 'target', 'value'],
                },
            },
        }}
    />
);
```

## Background Color

- **Key:** Background Color

```jsx
import React from 'react';
import Sankey from '@splunk/visualizations/Sankey';

export default () => (
    <Sankey
        options={{
            backgroundColor: 'pink',
        }}
        dataSources={{
            primary: {
                data: {
                    columns: [
                        ['Oil', 'Natural Gas', 'Coal', 'Coal', 'Fossil Fuels', 'Electricity'],
                        ['Fossil Fuels', 'Fossil Fuels', 'Fossil Fuels', 'Electricity', 'Energy', 'Energy'],
                        [15, 20, 25, 25, 60, 25],
                    ],
                    fields: ['source', 'target', 'value'],
                },
            },
        }}
    />
);
```

## Backward Links

- **Key:** Backward Links

```jsx
import React from 'react';
import Sankey from '@splunk/visualizations/Sankey';

export default () => (
    <Sankey
        dataSources={{
            primary: {
                data: {
                    columns: [
                        [
                            'Oil',
                            'Natural Gas',
                            'Coal',
                            'Coal',
                            'Fossil Fuels',
                            'Electricity',
                            'Electricity',
                            'Energy',
                        ],
                        [
                            'Fossil Fuels',
                            'Fossil Fuels',
                            'Fossil Fuels',
                            'Electricity',
                            'Energy',
                            'Energy',
                            'Electricity',
                            'Oil',
                        ],
                        [15, 20, 25, 25, 60, 25, 5, 2],
                    ],
                    fields: ['source', 'target', 'value'],
                },
            },
        }}
    />
);
```

## Specified Field for Link Values

- **Key:** Specified Field

```jsx
import React from 'react';
import Sankey from '@splunk/visualizations/Sankey';

export default () => (
    <Sankey
        options={{
            linkValues: '> primary | seriesByName("value2")',
        }}
        dataSources={{
            primary: {
                data: {
                    columns: [
                        ['Oil', 'Natural Gas', 'Coal', 'Coal', 'Fossil Fuels', 'Electricity'],
                        ['Fossil Fuels', 'Fossil Fuels', 'Fossil Fuels', 'Electricity', 'Energy', 'Energy'],
                        [15, 20, 25, 25, 60, 25],
                        [1, 20, 3, 4, 50, 6],
                    ],
                    fields: ['source', 'target', 'value', 'value2'],
                },
            },
        }}
    />
);
```

## Link Opacity

- **Key:** Link Opacity

```jsx
import React from 'react';
import Sankey from '@splunk/visualizations/Sankey';

export default () => (
    <Sankey
        options={{
            linkOpacity: 0.2,
        }}
        dataSources={{
            primary: {
                data: {
                    columns: [
                        ['Oil', 'Natural Gas', 'Coal', 'Coal', 'Fossil Fuels', 'Electricity'],
                        ['Fossil Fuels', 'Fossil Fuels', 'Fossil Fuels', 'Electricity', 'Energy', 'Energy'],
                        [15, 20, 25, 25, 60, 25],
                    ],
                    fields: ['source', 'target', 'value'],
                },
            },
        }}
    />
);
```

## Series Colors

- **Key:** Series Colors

```jsx
import React from 'react';
import Sankey from '@splunk/visualizations/Sankey';

export default () => (
    <Sankey
        options={{
            seriesColors: ['#9980FF', '#45D4BA', '#FB865C', '#66AAF9', '#E85B79', '#88EE66', '#F0B000'],
        }}
        dataSources={{
            primary: {
                data: {
                    columns: [
                        ['Oil', 'Natural Gas', 'Coal', 'Coal', 'Fossil Fuels', 'Electricity'],
                        ['Fossil Fuels', 'Fossil Fuels', 'Fossil Fuels', 'Electricity', 'Energy', 'Energy'],
                        [15, 20, 25, 25, 60, 25],
                    ],
                    fields: ['source', 'target', 'value'],
                },
            },
        }}
    />
);
```

## Link Colors

- **Key:** Link Colors

```jsx
import React from 'react';
import Sankey from '@splunk/visualizations/Sankey';

export default () => (
    <Sankey
        context={{
            linkColorRangeConfig: [
                { to: 20, value: '#D41F1F' },
                { from: 20, to: 40, value: '#D94E17' },
                { from: 40, to: 60, value: '#CBA700' },
                { from: 60, to: 80, value: '#669922' },
                { from: 80, value: '#118832' },
            ],
        }}
        options={{
            colorMode: 'dynamic',
        }}
        dataSources={{
            primary: {
                data: {
                    columns: [
                        ['Oil', 'Natural Gas', 'Coal', 'Coal', 'Fossil Fuels', 'Electricity'],
                        ['Fossil Fuels', 'Fossil Fuels', 'Fossil Fuels', 'Electricity', 'Energy', 'Energy'],
                        [15, 20, 25, 25, 60, 25],
                    ],
                    fields: ['source', 'target', 'value'],
                },
            },
        }}
    />
);
```

## Label Display

- **Key:** Link Colors

```jsx
import React from 'react';
import Sankey from '@splunk/visualizations/Sankey';

export default () => (
    <Sankey
        options={{
            labelDisplay: 'valuesAndPercentage',
            width: 940,
            height: 490,
        }}
        dataSources={{
            primary: {
                data: {
                    columns: [
                        [
                            'Total Spending',
                            'Total Spending',
                            'Total Spending',
                            'SCP',
                            'SCP',
                            'Security',
                            'Security',
                            'Security',
                            'Observability',
                            'Observability',
                        ],
                        [
                            'SCP',
                            'Security',
                            'Observability',
                            'SCP Policy Engine',
                            'Service Control API',
                            'IAM',
                            'Firewall',
                            'Encryption',
                            'Logging',
                            'Monitoring',
                        ],
                        [
                            5000000, 8000000, 7000000, 3000000, 2000000, 4000000, 2500000, 1500000, 4000000,
                            3000000,
                        ],
                    ],
                    fields: ['source', 'target', 'value'],
                },
            },
        }}
    />
);
```

## Unit

- **Key:** Unit

```jsx
import React from 'react';
import Sankey from '@splunk/visualizations/Sankey';

export default () => (
    <Sankey
        options={{
            labelDisplay: 'valuesAndPercentage',
            unit: '$',
        }}
        dataSources={{
            primary: {
                data: {
                    columns: [
                        ['Oil', 'Natural Gas', 'Coal', 'Coal', 'Fossil Fuels', 'Electricity'],
                        ['Fossil Fuels', 'Fossil Fuels', 'Fossil Fuels', 'Electricity', 'Energy', 'Energy'],
                        [15, 20, 25, 25, 60, 25],
                    ],
                    fields: ['source', 'target', 'value'],
                },
            },
        }}
    />
);
```

## Limit Results

- **Key:** Limit Results

```jsx
import React from 'react';
import Sankey from '@splunk/visualizations/Sankey';

export default () => (
    <Sankey
        options={{
            resultLimit: 4,
        }}
        dataSources={{
            primary: {
                data: {
                    columns: [
                        ['Oil', 'Natural Gas', 'Coal', 'Coal', 'Fossil Fuels', 'Electricity'],
                        ['Fossil Fuels', 'Fossil Fuels', 'Fossil Fuels', 'Electricity', 'Energy', 'Energy'],
                        [15, 20, 25, 25, 60, 25],
                    ],
                    fields: ['source', 'target', 'value'],
                },
            },
        }}
    />
);
```

## Dense Data

- **Key:** Dense Data

```jsx
import React from 'react';
import Sankey from '@splunk/visualizations/Sankey';

export default () => (
    <Sankey
        options={{
            width: 900,
            height: 600,
        }}
        dataSources={{
            primary: {
                data: {
                    columns: [
                        [
                            'Advocacy and Education',
                            'Advocacy and Education',
                            'Advocacy and Education',
                            'Advocacy and Education',
                            'Advocacy and Education',
                            'Contributions, Gifts & Grants',
                            'Contributions, Gifts & Grants',
                            'Contributions, Gifts & Grants',
                            'Contributions, Gifts & Grants',
                            'Contributions, Gifts & Grants',
                            'Contributions, Gifts & Grants',
                            'Contributions, Gifts & Grants',
                            'Contributions, Gifts & Grants',
                            'Development and Relief Services',
                            'Development and Relief Services',
                            'Development and Relief Services',
                            'Development and Relief Services',
                            'Development and Relief Services',
                            'Environmental Protection and Conservation',
                            'Environmental Protection and Conservation',
                            'Environmental Protection and Conservation',
                            'Environmental Protection and Conservation',
                            'Environmental Protection and Conservation',
                            'Fundraising Events',
                            'Fundraising Events',
                            'Fundraising Events',
                            'Fundraising Events',
                            'Fundraising Events',
                            'Fundraising Events',
                            'Fundraising Events',
                            'Fundraising Events',
                            'Government Grants',
                            'Government Grants',
                            'Government Grants',
                            'Government Grants',
                            'Government Grants',
                            'Government Grants',
                            'Government Grants',
                            'Government Grants',
                            'Homeless Services',
                            'Homeless Services',
                            'Homeless Services',
                            'Homeless Services',
                            'Medical Research',
                            'Medical Research',
                            'Medical Research',
                            'Medical Research',
                            'Medical Research',
                            'Multipurpose Human Service Organizations',
                            'Multipurpose Human Service Organizations',
                            'Multipurpose Human Service Organizations',
                            'Multipurpose Human Service Organizations',
                            'Multipurpose Human Service Organizations',
                            'Museums',
                            'Museums',
                            'Museums',
                            'Museums',
                            'Museums',
                            'Other Revenue',
                            'Other Revenue',
                            'Other Revenue',
                            'Other Revenue',
                            'Other Revenue',
                            'Other Revenue',
                            'Other Revenue',
                            'Other Revenue',
                            'Performing Arts',
                            'Performing Arts',
                            'Performing Arts',
                            'Performing Arts',
                            'Performing Arts',
                            'Program Service Revenue',
                            'Program Service Revenue',
                            'Program Service Revenue',
                            'Program Service Revenue',
                            'Program Service Revenue',
                            'Program Service Revenue',
                            'Program Service Revenue',
                            'Program Service Revenue',
                        ],
                        [
                            'Administrative Expenses',
                            'Deficit',
                            'Excess',
                            'Fundraising Expenses',
                            'Program Expenses',
                            'Advocacy and Education',
                            'Development and Relief Services',
                            'Environmental Protection and Conservation',
                            'Homeless Services',
                            'Medical Research',
                            'Multipurpose Human Service Organizations',
                            'Museums',
                            'Performing Arts',
                            'Administrative Expenses',
                            'Deficit',
                            'Excess',
                            'Fundraising Expenses',
                            'Program Expenses',
                            'Administrative Expenses',
                            'Deficit',
                            'Excess',
                            'Fundraising Expenses',
                            'Program Expenses',
                            'Advocacy and Education',
                            'Development and Relief Services',
                            'Environmental Protection and Conservation',
                            'Homeless Services',
                            'Medical Research',
                            'Multipurpose Human Service Organizations',
                            'Museums',
                            'Performing Arts',
                            'Advocacy and Education',
                            'Development and Relief Services',
                            'Environmental Protection and Conservation',
                            'Homeless Services',
                            'Medical Research',
                            'Multipurpose Human Service Organizations',
                            'Museums',
                            'Performing Arts',
                            'Administrative Expenses',
                            'Excess',
                            'Fundraising Expenses',
                            'Program Expenses',
                            'Administrative Expenses',
                            'Deficit',
                            'Excess',
                            'Fundraising Expenses',
                            'Program Expenses',
                            'Administrative Expenses',
                            'Deficit',
                            'Excess',
                            'Fundraising Expenses',
                            'Program Expenses',
                            'Administrative Expenses',
                            'Deficit',
                            'Excess',
                            'Fundraising Expenses',
                            'Program Expenses',
                            'Advocacy and Education',
                            'Development and Relief Services',
                            'Environmental Protection and Conservation',
                            'Homeless Services',
                            'Medical Research',
                            'Multipurpose Human Service Organizations',
                            'Museums',
                            'Performing Arts',
                            'Administrative Expenses',
                            'Deficit',
                            'Excess',
                            'Fundraising Expenses',
                            'Program Expenses',
                            'Advocacy and Education',
                            'Development and Relief Services',
                            'Environmental Protection and Conservation',
                            'Homeless Services',
                            'Medical Research',
                            'Multipurpose Human Service Organizations',
                            'Museums',
                            'Performing Arts',
                        ],
                        [
                            86048287, 19527597, 180998707, 102847712, 551149431, 692368620, 5168026746,
                            1348059493, 40397702, 3135201571, 596186305, 1134802008, 535612677, 380710374,
                            234695006, 301119719, 303222132, 6844599994, 223176655, 12910749, 200278135,
                            245605924, 1458686081, 35787203, 47996098, 24894387, 1489828, 1384896423,
                            47373812, 74954150, 68126458, 97922898, 1995467819, 177851864, 36400813,
                            452557152, 74042793, 289426307, 86150713, 8168643, 11849011, 5258340, 73010009,
                            600149733, 143027122, 425457173, 681830799, 5923646137, 159174125, 86842537,
                            93271044, 36180706, 1615801951, 360654482, 24558593, 457425006, 129388446,
                            1765421094, 45225660, 138826432, 153235160, 7518524, 695777987, 208603344,
                            824815361, 169700551, 135910859, 36234508, 140192511, 93937162, 1142671094,
                            27444378, 156203421, 384935669, 11863706, 1777488301, 832724174, 273125661,
                            600421167,
                        ],
                    ],
                    fields: ['source', 'target', 'value'],
                },
            },
        }}
    />
);
```
