# chart-bubble

> Bubble chart comparing internet adoption and growth for global markets.

**Framework:** react  **Component:** Chart  **Variant:** bubble

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/react/ts/chart-bubble.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-react-charts
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/chart-bubble/Chart.tsx

```tsx

import { useRef } from 'react';
import {
    ChartComponent,
    SeriesCollectionDirective,
    SeriesDirective,
    Inject,
    BubbleSeries,
    Tooltip,
    Legend,
    type IPointRenderEventArgs,
    type ILegendRenderEventArgs,
    DataLabel
} from '@syncfusion/ej2-react-charts';
import { Browser } from '@syncfusion/ej2-base';

interface CountryData {
    x: number;
    y: number;
    size: number;
    country: string;
    text: string;
    region: string;
    tooltip: string;
}

interface RegionStyle {
    fill: string;
    border: string;
    start: string;
    end: string;
}

const data: CountryData[] = [
    { x: 92.2, y: 7.8, size: 1.41, country: 'China', text: 'China', region: 'Asia', tooltip: 'China' },
    { x: 74.0, y: 6.5, size: 1.45, country: 'India', text: 'India', region: 'Asia', tooltip: 'India' },
    { x: 90.4, y: 6.0, size: 0.28, country: 'Indonesia', text: 'Indonesia', region: 'Asia', tooltip: 'Indonesia' },
    { x: 99.4, y: 2.2, size: 0.34, country: 'United States', text: 'US', region: 'North America', tooltip: 'United States' },
    { x: 88.6, y: 1.3, size: 0.21, country: 'Brazil', text: 'Brazil', region: 'South America', tooltip: 'Brazil' },
    { x: 99.0, y: 0.7, size: 0.084, country: 'Germany', text: 'Germany', region: 'Europe', tooltip: 'Germany' },
    { x: 72.0, y: 2.0, size: 0.114, country: 'Egypt', text: 'Egypt', region: 'Africa', tooltip: 'Egypt' },
    { x: 99.6, y: 3.4, size: 0.144, country: 'Russia', text: 'Russia', region: 'Europe', tooltip: 'Russia' },
    { x: 96.5, y: 0.2, size: 0.123, country: 'Japan', text: 'Japan', region: 'Asia', tooltip: 'Japan' },
    { x: 86.1, y: 4.0, size: 0.024, country: 'Mali', text: 'MLI', region: 'Africa', tooltip: 'Mali' },
    { x: 92.6, y: 5.2, size: 0.117, country: 'Philippines', text: 'PH', region: 'Asia', tooltip: 'Philippines' },
    { x: 61.3, y: 1.45, size: 0.232, country: 'Nigeria', text: 'Nigeria', region: 'Africa', tooltip: 'Nigeria' },
    { x: 82.2, y: 3.97, size: 0.0075, country: 'Hong Kong', text: 'Hong Kong', region: 'Asia', tooltip: 'Hong Kong' },
    { x: 79.2, y: 4.9, size: 0.018, country: 'Netherlands', text: 'NL', region: 'Europe', tooltip: 'Netherlands' },
    { x: 72.5, y: 4.5, size: 0.011, country: 'Jordan', text: 'Jordan', region: 'Asia', tooltip: 'Jordan' },
    { x: 81.0, y: 2.5, size: 0.027, country: 'Australia', text: 'Australia', region: 'Oceania', tooltip: 'Australia' },
    { x: 66.8, y: 3.9, size: 0.0035, country: 'Mongolia', text: 'MN', region: 'Asia', tooltip: 'Mongolia' },
    { x: 78.4, y: 2.9, size: 0.023, country: 'Taiwan', text: 'Taiwan', region: 'Asia', tooltip: 'Taiwan' }
];

const regionStyles: Record<string, RegionStyle> = {
    Asia: {
        fill: '#A7E3DF',
        border: '#0F766E',
        start: '#E0F7F4',
        end: '#70CEC4'
    },
    Europe: {
        fill: '#FFD6A5',
        border: '#C2410C',
        start: '#FFF0D9',
        end: '#FDBA74'
    },
    Africa: {
        fill: '#FFBFC3',
        border: '#BE123C',
        start: '#FFE4E6',
        end: '#FDA4AF'
    },
    'North America': {
        fill: '#BFDBFE',
        border: '#1D4ED8',
        start: '#EFF6FF',
        end: '#93C5FD'
    },
    'South America': {
        fill: '#FBCFE8',
        border: '#BE185D',
        start: '#FCE7F3',
        end: '#F9A8D4'
    },
    Oceania: {
        fill: '#DDD6FE',
        border: '#6D28D9',
        start: '#F3E8FF',
        end: '#C4B5FD'
    }
};

const legendTemplate: string =
    '<div style="display:flex;align-items:center;gap:' +
    (Browser.isDevice ? '4px' : '8px') +
    ';white-space:nowrap;opacity:1;padding:4px 8px;">' +
    '<span style="display:inline-block;width:12px;height:12px;flex-shrink:0;' +
    'border-radius:50%;border:2px solid;box-sizing:border-box;"></span>' +
    '<span class="legend-label" style="display:inline-block;font-size:' +
    (Browser.isDevice ? '9px' : '13px') +
    ';white-space:nowrap;"></span>' +
    '</div>';

const SAMPLE_CSS = `
    .country-development {
        width: 100%;
        padding: 16px;
        box-sizing: border-box;
        background: #ffffff;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        font-family: Arial, sans-serif;
    }

    .country-development .sample-title {
        text-align: center;
        color: #1e293b;
        font-size: 23px;
        font-weight: 600;
        margin: 8px 0 4px;
    }

    .country-development .sample-subtitle {
        text-align: center;
        color: #64748b;
        font-size: 13px;
        margin-bottom: 12px;
    }

    .country-development .sample-footer {
        text-align: center;
        color: #64748b;
        font-size: 11px;
        margin-top: 8px;
    }

    @media (max-width: 600px) {
        .country-development {
            padding: 8px;
        }

        .country-development .sample-title {
            font-size: 18px;
        }
    }
`;

const Bubble = () => {
    const chartRef = useRef<ChartComponent | null>(null);

    const loaded = (): void => {
        const chart = document.getElementById('country-development-chart');

        if (chart) {
            chart.setAttribute('title', '');
        }

        addBubbleGradients();
    };

    // Create SVG gradients inside the chart SVG.
    const addBubbleGradients = (): void => {
        const chartElement = document.getElementById('country-development-chart');
        const svg = chartElement?.querySelector('svg');

        if (!svg) {
            return;
        }

        const existingDefs = svg.querySelector('#country-bubble-gradients');

        if (existingDefs) {
            existingDefs.remove();
        }

        const svgNS = 'http://www.w3.org/2000/svg';
        const defs = document.createElementNS(svgNS, 'defs');
        defs.setAttribute('id', 'country-bubble-gradients');

        Object.entries(regionStyles).forEach(([, style], index) => {
            const gradient = document.createElementNS(svgNS, 'linearGradient');
            const gradientId = `country-gradient-${index}`;

            gradient.setAttribute('id', gradientId);
            gradient.setAttribute('x1', '0%');
            gradient.setAttribute('y1', '0%');
            gradient.setAttribute('x2', '100%');
            gradient.setAttribute('y2', '100%');

            const start = document.createElementNS(svgNS, 'stop');
            start.setAttribute('offset', '0%');
            start.setAttribute('stop-color', style.start);

            const end = document.createElementNS(svgNS, 'stop');
            end.setAttribute('offset', '100%');
            end.setAttribute('stop-color', style.end);

            gradient.appendChild(start);
            gradient.appendChild(end);
            defs.appendChild(gradient);
        });

        svg.insertBefore(defs, svg.firstChild);
    };

    const pointRender = (args: IPointRenderEventArgs): void => {
        const point = data[args.point.index];

        if (!point) {
            return;
        }

        const style = regionStyles[point.region];
        const regionIndex = Object.keys(regionStyles).indexOf(point.region);

        args.fill = `url(#country-gradient-${regionIndex})`;
        args.border = {
            color: style.border,
            width: 2
        };
    };

    // Customize the legend template.
    const legendRender = (args: ILegendRenderEventArgs): void => {
        const chart = chartRef.current;
        const matchedSeries = chart && chart.series
            ? chart.series.find((series) => series.name === args.text)
            : null;

        const opacity = matchedSeries && !matchedSeries.visible ? '0.5' : '1';

        if (!args.template) {
            return;
        }

        args.template = args.template
            .replace('opacity:1;', 'opacity:' + opacity + ';')
            .replace(
                'border:2px solid;',
                'background:linear-gradient(135deg, #E0F7F4, #70CEC4);' +
                'border:2px solid #0F766E;'
            )
            .replace(
                '<span class="legend-label" style="display:inline-block;font-size:' +
                (Browser.isDevice ? '9px' : '13px') +
                ';white-space:nowrap;"></span>',
                '<span class="legend-label" style="display:inline-block;' +
                'font-size:' + (Browser.isDevice ? '9px' : '13px') +
                ';white-space:nowrap;color:#0F766E;font-weight:bold;">' +
                args.text + '</span>'
            );
    };

    return (
        <div className="control-pane country-development">
            <style>{SAMPLE_CSS}</style>

            <div className="sample-title">
                Global Country Development and Economic Analysis
            </div>

            <div className="sample-subtitle">
                Internet penetration, GDP growth and population comparison
            </div>

            <div className="control-section">
                <ChartComponent
                    id="country-development-chart"
                    ref={(chart: ChartComponent | null) => {
                        chartRef.current = chart;
                    }}
                    style={{ textAlign: 'center' }}
                    width="100%"
                    height="480px"
                    loaded={loaded}
                    pointRender={pointRender}
                    legendRender={legendRender}
                    primaryXAxis={{
                        minimum: 65,
                        maximum: 102,
                        interval: 5,
                        title: 'Internet Penetration (%)',
                        labelFormat: '{value}%',
                        majorGridLines: {
                            width: 1,
                            color: '#e2e8f0'
                        },
                        lineStyle: {
                            width: 1,
                            color: '#cbd5e1'
                        }
                    }}
                    primaryYAxis={{
                        minimum: 0,
                        maximum: 10,
                        interval: 2.5,
                        title: 'GDP Growth (%)',
                        labelFormat: '{value}%',
                        majorGridLines: {
                            width: 1,
                            color: '#e2e8f0'
                        },
                        lineStyle: {
                            width: 1,
                            color: '#cbd5e1'
                        }
                    }}
                    legendSettings={{
                        visible: true,
                        position: 'Top',
                        template: legendTemplate
                    }}
                    tooltip={{
                        enable: true,
                        enableMarker: false,
                        header: '<b>${point.tooltip}</b>',
                        format:
                            'Internet Penetration: <b>${point.x}</b><br/>' +
                            'GDP Growth: <b>${point.y}</b><br/>' +
                            'Population: <b>${point.size} Billion</b>'
                    }}
                    chartArea={{
                        border: { width: 0 }
                    }}
                    background="transparent"
                >
                    <Inject services={[
                        BubbleSeries,
                        Tooltip,
                        Legend,
                        DataLabel
                    ]} />

                    <SeriesCollectionDirective>
                        <SeriesDirective
                            dataSource={data}
                            name="Countries"
                            type="Bubble"
                            xName="x"
                            yName="y"
                            size="size"
                            minRadius={3}
                            maxRadius={8}
                            tooltipMappingName="tooltip"
                            border={{
                                width: 2
                            }}
                            marker={{
                                dataLabel: {
                                    visible: true,
                                    name: 'text',
                                    position: 'Middle',
                                    font: {
                                        fontWeight: '600',
                                        color: '#263449',
                                        size: '11px'
                                    }
                                }
                            }}
                        />
                    </SeriesCollectionDirective>
                </ChartComponent>
            </div>

            <div className="sample-footer">
                Bubble size represents population. Gradient colors represent geographic regions.
            </div>
        </div>
    );
};

export default Bubble;

```
