# Pie Examples

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

## Basic Pie

- **Key:** Basic Pie

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

export default () => (
    <Pie
        options={{}}
        dataSources={{
            primary: {
                requestParams: { offset: 0, count: 20 },
                data: {
                    fields: [{ name: 'component' }, { name: 'count' }],
                    columns: [
                        [
                            'January',
                            'February',
                            'March',
                            'April',
                            'May',
                            'June',
                            'July',
                            'August',
                            'September',
                            'October',
                            'November',
                            'December',
                        ],
                        ['1', '1', '1', '2', '10', '10', '5', '5', '5', '5', '5', '50'],
                    ],
                },
                meta: { totalCount: 20 },
            },
        }}
    />
);
```

## Background Color - Orange

- **Key:** Background Color

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

export default () => (
    <Pie
        options={{ backgroundColor: '#f29335' }}
        dataSources={{
            primary: {
                requestParams: { offset: 0, count: 20 },
                data: {
                    fields: [{ name: 'component' }, { name: 'count' }],
                    columns: [
                        [
                            'January',
                            'February',
                            'March',
                            'April',
                            'May',
                            'June',
                            'July',
                            'August',
                            'September',
                            'October',
                            'November',
                            'December',
                        ],
                        ['1', '1', '1', '2', '10', '10', '5', '5', '5', '5', '5', '50'],
                    ],
                },
                meta: { totalCount: 20 },
            },
        }}
    />
);
```

## Collapse Label - New Label

- **Key:** Collapsinglabel

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

export default () => (
    <Pie
        options={{ collapseLabel: 'New Collapsing Label' }}
        dataSources={{
            primary: {
                requestParams: { offset: 0, count: 20 },
                data: {
                    fields: [{ name: 'component' }, { name: 'count' }],
                    columns: [
                        [
                            'January',
                            'February',
                            'March',
                            'April',
                            'May',
                            'June',
                            'July',
                            'August',
                            'September',
                            'October',
                            'November',
                            'December',
                        ],
                        ['1', '1', '1', '2', '10', '10', '5', '5', '5', '5', '5', '50'],
                    ],
                },
                meta: { totalCount: 20 },
            },
        }}
    />
);
```

## Collapse Threshold - 5

- **Key:** Slicecollapsingthreshold

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

export default () => (
    <Pie
        options={{ collapseThreshold: 0.05 }}
        dataSources={{
            primary: {
                requestParams: { offset: 0, count: 20 },
                data: {
                    fields: [{ name: 'component' }, { name: 'count' }],
                    columns: [
                        [
                            'January',
                            'February',
                            'March',
                            'April',
                            'May',
                            'June',
                            'July',
                            'August',
                            'September',
                            'October',
                            'November',
                            'December',
                        ],
                        ['1', '1', '1', '2', '10', '10', '5', '5', '5', '5', '5', '50'],
                    ],
                },
                meta: { totalCount: 20 },
            },
        }}
    />
);
```

## Label Display - Percent

- **Key:** Labelswithpercentpie

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

export default () => (
    <Pie
        options={{ labelDisplay: 'valuesAndPercentage' }}
        dataSources={{
            primary: {
                requestParams: { offset: 0, count: 20 },
                data: {
                    fields: [{ name: 'component' }, { name: 'count' }],
                    columns: [
                        [
                            'January',
                            'February',
                            'March',
                            'April',
                            'May',
                            'June',
                            'July',
                            'August',
                            'September',
                            'October',
                            'November',
                            'December',
                        ],
                        ['1', '1', '1', '2', '10', '10', '5', '5', '5', '5', '5', '50'],
                    ],
                },
                meta: { totalCount: 20 },
            },
        }}
    />
);
```

## Label Display - Count

- **Key:** Labelswithcountpie

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

export default () => (
    <Pie
        options={{ labelDisplay: 'count' }}
        dataSources={{
            primary: {
                requestParams: { offset: 0, count: 20 },
                data: {
                    fields: [{ name: 'component' }, { name: 'count' }],
                    columns: [
                        [
                            'January',
                            'February',
                            'March',
                            'April',
                            'May',
                            'June',
                            'July',
                            'August',
                            'September',
                            'October',
                            'November',
                            'December',
                        ],
                        ['1', '1', '1', '2', '10', '10', '5', '5', '5', '5', '5', '50'],
                    ],
                },
                meta: { totalCount: 20 },
            },
        }}
    />
);
```

## Label Display - Values and Count

- **Key:** Labelswithvalueandcountpie

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

export default () => (
    <Pie
        options={{ labelDisplay: 'valuesAndCount' }}
        dataSources={{
            primary: {
                requestParams: { offset: 0, count: 20 },
                data: {
                    fields: [{ name: 'component' }, { name: 'count' }],
                    columns: [
                        [
                            'January',
                            'February',
                            'March',
                            'April',
                            'May',
                            'June',
                            'July',
                            'August',
                            'September',
                            'October',
                            'November',
                            'December',
                        ],
                        ['1', '1', '1', '2', '10', '10', '5', '5', '5', '5', '5', '50'],
                    ],
                },
                meta: { totalCount: 20 },
            },
        }}
    />
);
```

## Label Display - Values, Percent, and Count

- **Key:** Labelswithpercentandcountpie

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

export default () => (
    <Pie
        options={{ labelDisplay: 'all' }}
        dataSources={{
            primary: {
                requestParams: { offset: 0, count: 20 },
                data: {
                    fields: [{ name: 'component' }, { name: 'count' }],
                    columns: [
                        [
                            'January',
                            'February',
                            'March',
                            'April',
                            'May',
                            'June',
                            'July',
                            'August',
                            'September',
                            'October',
                            'November',
                            'December',
                        ],
                        ['1', '1', '1', '2', '10', '10', '5', '5', '5', '5', '5', '50'],
                    ],
                },
                meta: { totalCount: 20 },
            },
        }}
    />
);
```

## Label Display - Off

- **Key:** Nolabelspie

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

export default () => (
    <Pie
        options={{ labelDisplay: 'off' }}
        dataSources={{
            primary: {
                requestParams: { offset: 0, count: 20 },
                data: {
                    fields: [{ name: 'component' }, { name: 'count' }],
                    columns: [
                        [
                            'January',
                            'February',
                            'March',
                            'April',
                            'May',
                            'June',
                            'July',
                            'August',
                            'September',
                            'October',
                            'November',
                            'December',
                        ],
                        ['1', '1', '1', '2', '10', '10', '5', '5', '5', '5', '5', '50'],
                    ],
                },
                meta: { totalCount: 20 },
            },
        }}
    />
);
```

## Result Limit - 5

- **Key:** Truncatedsizepie

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

export default () => (
    <Pie
        options={{ resultLimit: '5' }}
        dataSources={{
            primary: {
                requestParams: { offset: 0, count: 20 },
                data: {
                    fields: [{ name: 'component' }, { name: 'count' }],
                    columns: [
                        [
                            'January',
                            'February',
                            'March',
                            'April',
                            'May',
                            'June',
                            'July',
                            'August',
                            'September',
                            'October',
                            'November',
                            'December',
                        ],
                        ['1', '1', '1', '2', '10', '10', '5', '5', '5', '5', '5', '50'],
                    ],
                },
                meta: { totalCount: 20 },
            },
        }}
    />
);
```

## Series Colors: Yellow, Blue, Green

- **Key:** Series Colors

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

export default () => (
    <Pie
        options={{ seriesColors: ['#FFFF00', '#0000FF', '#008000'] }}
        dataSources={{
            primary: {
                requestParams: { offset: 0, count: 20 },
                data: {
                    fields: [{ name: 'component' }, { name: 'count' }],
                    columns: [
                        [
                            'January',
                            'February',
                            'March',
                            'April',
                            'May',
                            'June',
                            'July',
                            'August',
                            'September',
                            'October',
                            'November',
                            'December',
                        ],
                        ['1', '1', '1', '2', '10', '10', '5', '5', '5', '5', '5', '50'],
                    ],
                },
                meta: { totalCount: 20 },
            },
        }}
    />
);
```

## Series Colors by Field: December - Green, May - Red

- **Key:** Field Colors

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

export default () => (
    <Pie
        options={{
            seriesColorsByField: { December: '#008000', May: '#FF0000' },
        }}
        dataSources={{
            primary: {
                requestParams: { offset: 0, count: 20 },
                data: {
                    fields: [{ name: 'component' }, { name: 'count' }],
                    columns: [
                        [
                            'January',
                            'February',
                            'March',
                            'April',
                            'May',
                            'June',
                            'July',
                            'August',
                            'September',
                            'October',
                            'November',
                            'December',
                        ],
                        ['1', '1', '1', '2', '10', '10', '5', '5', '5', '5', '5', '50'],
                    ],
                },
                meta: { totalCount: 20 },
            },
        }}
    />
);
```

## Show Donut Hole - True

- **Key:** Donut

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

export default () => (
    <Pie
        options={{
            showDonutHole: true,
        }}
        dataSources={{
            primary: {
                requestParams: { offset: 0, count: 20 },
                data: {
                    fields: [{ name: 'component' }, { name: 'count' }],
                    columns: [
                        [
                            'January',
                            'February',
                            'March',
                            'April',
                            'May',
                            'June',
                            'July',
                            'August',
                            'September',
                            'October',
                            'November',
                            'December',
                        ],
                        ['1', '1', '1', '2', '10', '10', '5', '5', '5', '5', '5', '50'],
                    ],
                },
                meta: { totalCount: 20 },
            },
        }}
    />
);
```

## Collapse - Exclude zeros and non-numeric values in the consolidated slice.

- **Key:** Collapse Exclude Zero

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

export default () => (
    <Pie
        options={{ collapseExcludeZero: true }}
        dataSources={{
            primary: {
                requestParams: { offset: 0, count: 20 },
                data: {
                    fields: [{ name: 'component' }, { name: 'count' }],
                    columns: [
                        [
                            'a',
                            'b',
                            'c',
                            'd',
                            'e',
                            'f',
                            'g',
                            'h',
                            'i',
                            'j',
                            'k',
                            'l',
                            'm',
                            'n',
                            'o',
                            'p',
                            'q',
                            'r',
                            's',
                            't',
                            'u',
                            'v',
                            'w',
                            'x',
                            'y',
                            'z',
                        ],
                        [
                            '0',
                            '0',
                            '0',
                            '1',
                            '1',
                            '1',
                            '86',
                            '98',
                            '29',
                            '13',
                            '68',
                            '60',
                            '44',
                            '73',
                            '63',
                            '57',
                            '36',
                            '31',
                            '42',
                            '58',
                            '86',
                            '44',
                            '62',
                            '97',
                            '90',
                            '97',
                        ],
                    ],
                },
                meta: { totalCount: 20 },
            },
        }}
    />
);
```

## Trellis

- **Key:** Trellis

```jsx
import React from 'react';
import { FeatureFlagContextProvider } from '@splunk/visualization-context/FeatureFlagContext';
import Pie from '@splunk/visualizations/Pie';

export default () => (
    <FeatureFlagContextProvider value={{ visualizations_enableTrellis: true }}>
        <Pie
            height={400}
            options={{
                splitByLayout: 'trellis',
                trellisSplitBy: 'month',
                trellis: {
                    minColumnWidth: 200,
                },
            }}
            dataSources={{
                primary: {
                    data: {
                        fields: [
                            {
                                name: 'component',
                                groupby_rank: '0',
                            },
                            {
                                name: 'month',
                                groupby_rank: '1',
                            },
                            {
                                name: 'count',
                            },
                        ],
                        columns: [
                            [
                                'Database',
                                'API',
                                'UI',
                                'Database',
                                'API',
                                'UI',
                                'Database',
                                'API',
                                'UI',
                                'Database',
                                'API',
                                'UI',
                                'Database',
                                'API',
                                'UI',
                                'Database',
                                'API',
                                'UI',
                            ],
                            [
                                'January',
                                'January',
                                'January',
                                'March',
                                'March',
                                'March',
                                'May',
                                'May',
                                'May',
                                'July',
                                'July',
                                'July',
                                'September',
                                'September',
                                'September',
                                'November',
                                'November',
                                'November',
                            ],
                            [
                                '45',
                                '32',
                                '23',
                                '42',
                                '35',
                                '28',
                                '52',
                                '38',
                                '30',
                                '48',
                                '35',
                                '27',
                                '50',
                                '40',
                                '25',
                                '47',
                                '36',
                                '29',
                            ],
                        ],
                    },
                    meta: {},
                },
            }}
        />
    </FeatureFlagContextProvider>
);
```
