# chart-bubble

> Bubble chart comparing internet penetration, GDP, and population across world regions with custom legend.

**Framework:** angular  **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/angular/chart-bubble.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-angular-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/bubble.component.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">
        <ejs-chart #chart id="country-development-chart" style="display: block; text-align: center;"
            width="100%" height="480px" background="transparent"
            [primaryXAxis]="primaryXAxis" [primaryYAxis]="primaryYAxis"
            [legendSettings]="legendSettings" [tooltip]="tooltip" [chartArea]="chartArea"
            (loaded)="loaded($event)" (pointRender)="pointRender($event)" (legendRender)="legendRender($event)">
            <e-series-collection>
                <e-series [dataSource]="data" name="Countries" type="Bubble" xName="x" yName="y" size="size"
                    [minRadius]="3" [maxRadius]="8" tooltipMappingName="tooltip"
                    [border]="border" [marker]="marker"></e-series>
            </e-series-collection>
        </ejs-chart>
    </div>

    <div class="sample-footer">
        Bubble size represents population. Gradient colors represent geographic regions.
    </div>
</div>

```

### src/components/chart-bubble/bubble.component.ts

```typescript
import { Component, ViewChild, ViewEncapsulation } from '@angular/core';
import {
    ChartModule,
    ChartComponent,
    BubbleSeriesService,
    TooltipService,
    LegendService,
    DataLabelService,
    type IPointRenderEventArgs,
    type ILegendRenderEventArgs,
    type AxisModel,
    type LegendSettingsModel,
    type TooltipSettingsModel,
    type MarkerSettingsModel,
    type BorderModel,
    type ChartAreaModel,
    type SeriesModel,
    ILoadedEventArgs
} from '@syncfusion/ej2-angular-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 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>';

@Component({
    selector: 'app-bubble',
    standalone: true,
    imports: [ChartModule],
    providers: [BubbleSeriesService, TooltipService, LegendService, DataLabelService],
    templateUrl: './bubble.component.html',
    styleUrls: ['../styles/bubble.component.css'],
    encapsulation: ViewEncapsulation.None
})
export class BubbleComponent {
    @ViewChild('chart')
    public chart?: ChartComponent;

    public 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' }
    ];

    public 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' }
    };

    public primaryXAxis: AxisModel = {
        minimum: 65,
        maximum: 102,
        interval: 5,
        title: 'Internet Penetration (%)',
        labelFormat: '{value}%',
        majorGridLines: { width: 1, color: '#e2e8f0' },
        lineStyle: { width: 1, color: '#cbd5e1' }
    };

    public primaryYAxis: AxisModel = {
        minimum: 0,
        maximum: 10,
        interval: 2.5,
        title: 'GDP Growth (%)',
        labelFormat: '{value}%',
        majorGridLines: { width: 1, color: '#e2e8f0' },
        lineStyle: { width: 1, color: '#cbd5e1' }
    };

    public legendSettings: LegendSettingsModel = {
        visible: true,
        position: 'Top',
        template: legendTemplate
    };

    public tooltip: TooltipSettingsModel = {
        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>'
    };

    public chartArea: ChartAreaModel = { border: { width: 0 } };

    public border: BorderModel = { width: 2 };

    public marker: MarkerSettingsModel = {
        dataLabel: {
            visible: true,
            name: 'text',
            position: 'Middle',
            font: { fontWeight: '600', color: '#263449', size: '11px' }
        }
    };

    public loaded(args: ILoadedEventArgs): void {
        const chartElement: HTMLElement | null = document.getElementById('country-development-chart');

        if (chartElement) {
            chartElement.setAttribute('title', '');
        }

        this.addBubbleGradients();
    }

    // Create SVG gradients inside the chart SVG.
    private 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(this.regionStyles).forEach((region: string, index: number) => {
            const style: RegionStyle = this.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);
    }

    public pointRender(args: IPointRenderEventArgs): void {
        const point: CountryData = this.data[args.point.index];

        if (!point) {
            return;
        }

        const style: RegionStyle = this.regionStyles[point.region];
        const regionIndex: number = Object.keys(this.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.
    public legendRender(args: ILegendRenderEventArgs): void {
        const matchedSeries: SeriesModel | undefined = this.chart && this.chart.series
            ? this.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>'
            );
    }
}

```
