# chart-bubble

> Bubble chart comparing internet penetration, GDP, and population across world regions.

**Framework:** javascript  **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/javascript/chart-bubble.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-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/index.html

```html
<div class="control-pane country-development">
    <div class="sample-title">
        Global Country Development and Economic Analysis
    </div>

    <div class="sample-subtitle">
        Internet penetration, GDP growth and population comparison
    </div>

    <div class="control-section">
        <div id="country-development-chart" style="text-align: center;"></div>
    </div>

    <div class="sample-footer">
        Bubble size represents population. Gradient colors represent geographic regions.
    </div>
</div>

<style>
    .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;
        }
    }
</style>

```

### src/components/chart-bubble/index.ts

```typescript
import {
    Chart,
    BubbleSeries,
    Tooltip,
    Legend,
    DataLabel,
    type IPointRenderEventArgs,
    type ILoadedEventArgs,
    type ILegendRenderEventArgs,
    type SeriesModel
} from '@syncfusion/ej2-charts';
import { Browser } from '@syncfusion/ej2-base';

Chart.Inject(BubbleSeries, Tooltip, Legend, DataLabel);

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>';

// Create SVG gradients inside the chart SVG.
const addBubbleGradients = (): void => {
    const chartElement: HTMLElement | null = document.getElementById('country-development-chart');
    const svg: SVGSVGElement | null | undefined = chartElement?.querySelector('svg');

    if (!svg) {
        return;
    }

    const existingDefs: Element | null = svg.querySelector('#country-bubble-gradients');

    if (existingDefs) {
        existingDefs.remove();
    }

    const svgNS: string = 'http://www.w3.org/2000/svg';
    const defs: Element = document.createElementNS(svgNS, 'defs');
    defs.setAttribute('id', 'country-bubble-gradients');

    Object.keys(regionStyles).forEach((region: string, index: number) => {
        const style: RegionStyle = regionStyles[region];
        const gradient: Element = document.createElementNS(svgNS, 'linearGradient');

        gradient.setAttribute('id', 'country-gradient-' + index);
        gradient.setAttribute('x1', '0%');
        gradient.setAttribute('y1', '0%');
        gradient.setAttribute('x2', '100%');
        gradient.setAttribute('y2', '100%');

        const start: Element = document.createElementNS(svgNS, 'stop');
        start.setAttribute('offset', '0%');
        start.setAttribute('stop-color', style.start);

        const end: Element = 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 chart: Chart = new Chart({
    width: '100%',
    height: '480px',
    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',
    series: [
        {
            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' }
                }
            }
        }
    ],
    loaded: (args: ILoadedEventArgs): void => {
        const chartElement: HTMLElement | null = document.getElementById('country-development-chart');

        if (chartElement) {
            chartElement.setAttribute('title', '');
        }

        addBubbleGradients();
    },
    pointRender: (args: IPointRenderEventArgs): void => {
        const point: CountryData = data[args.point.index];

        if (!point) {
            return;
        }

        const style: RegionStyle = regionStyles[point.region];
        const regionIndex: number = Object.keys(regionStyles).indexOf(point.region);

        args.fill = 'url(#country-gradient-' + regionIndex + ')';
        args.border = { color: style.border, width: 2 };
    },
    // Legend template customization following the Olympic Medal sample.
    legendRender: (args: ILegendRenderEventArgs): void => {
        const matchedSeries: SeriesModel | undefined = chart && chart.series
            ? chart.series.find((series: SeriesModel) => series.name === args.text)
            : undefined;

        const opacity: string = matchedSeries && !matchedSeries.visible ? '0.5' : '1';

        args.template = (args.template as string)
            .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>'
            );
    }
});
chart.appendTo('#country-development-chart');

```
