Angular Widgets

Widgets

Angular widget components give information about the app statistics.

Available in Other JavaScript Frameworks

CoreUI Angular Widgets is also available for React and Vue. Explore framework-specific implementations below:

See: how to import required CoreUI Icons

Examples

Widget Stats A

Create custom Widget variants with cTemplateId:

  • widgetValueTemplate
  • widgetActionTemplate
  • widgetChartTemplate
import { RouterLink } from '@angular/router';
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';

import {
  ButtonDirective,
  ColComponent,
  DropdownComponent,
  DropdownItemDirective,
  DropdownMenuDirective,
  DropdownToggleDirective,
  RowComponent,
  TemplateIdDirective,
  WidgetStatAComponent
} from '@coreui/angular';
import { ChartjsComponent } from '@coreui/angular-chartjs';
import { cilArrowTop, cilOptions } from '@coreui/icons';
import { IconDirective } from '@coreui/icons-angular';
import { getStyle } from '@coreui/utils';

@Component({
  selector: 'docs-widgets-stats',
  templateUrl: './widgets-stats.component.html',
  standalone: true,
  changeDetection: ChangeDetectionStrategy.Eager,
  imports: [
    RowComponent,
    ColComponent,
    WidgetStatAComponent,
    TemplateIdDirective,
    IconDirective,
    DropdownComponent,
    ButtonDirective,
    DropdownToggleDirective,
    DropdownMenuDirective,
    DropdownItemDirective,
    RouterLink,
    ChartjsComponent
  ]
})
export class WidgetsStatsComponent implements OnInit {
  icons = { cilOptions, cilArrowTop };

  data: any = {};
  options: any = {};

  labels = [
    'January',
    'February',
    'March',
    'April',
    'May',
    'June',
    'July',
    'August',
    'September',
    'October',
    'November',
    'December',
    'January',
    'February',
    'March',
    'April'
  ];

  datasets = [
    {
      label: 'My First dataset',
      backgroundColor: 'transparent',
      borderColor: 'rgba(255,255,255,.55)',
      pointBackgroundColor: getStyle('--cui-primary'),
      pointHoverBorderColor: getStyle('--cui-primary'),
      data: [65, 59, 84, 84, 51, 55, 40]
    }
  ];

  optionsDefault = {
    plugins: {
      legend: {
        display: false
      }
    },
    maintainAspectRatio: true,
    scales: {
      x: {
        grid: {
          display: false,
          drawBorder: false
        },
        ticks: {
          display: false
        }
      },
      y: {
        min: 30,
        max: 89,
        display: false,
        grid: {
          display: false
        },
        ticks: {
          display: false
        }
      }
    },
    elements: {
      line: {
        borderWidth: 1,
        tension: 0.4
      },
      point: {
        radius: 4,
        hitRadius: 10,
        hoverRadius: 4
      }
    }
  };

  ngOnInit(): void {
    this.data = {
      labels: this.labels.slice(0, 7),
      datasets: this.datasets
    };
    this.options = this.optionsDefault;
  }
}
<c-row>
  <c-col md="12" xl="6">
    <c-widget-stat-a
      class="mb-4"
      color="primary"
      [title]="'Widget Title'"
    >
      <ng-template cTemplateId="widgetValueTemplate" ngPreserveWhitespaces>
        $9000
        <span class="fs-6 fw-normal">
      (40.9% <svg [cIcon]="icons.cilArrowTop"></svg>)
    </span>
      </ng-template>
      <ng-template cTemplateId="widgetActionTemplate">
        <c-dropdown alignment="end" variant="btn-group">
          <button [caret]="false" cButton cDropdownToggle class="p-0" color="transparent">
            <svg [cIcon]="icons.cilOptions" class="text-high-emphasis-inverse"></svg>
          </button>
          <div cDropdownMenu>
            <a [routerLink]="[]" cDropdownItem>Action One</a>
            <a [routerLink]="[]" cDropdownItem>Action Two</a>
            <a [routerLink]="[]" cDropdownItem>Action Three</a>
          </div>
        </c-dropdown>
      </ng-template>
      <ng-template cTemplateId="widgetChartTemplate">
        <c-chart [data]="data" [options]="options" class="mt-3 mx-3" height="110" type="line" />
      </ng-template>
    </c-widget-stat-a>
  </c-col>
</c-row>

Widget Stats B

import { Component, computed, signal } from '@angular/core';
import { ColComponent, ProgressComponent, RowComponent, WidgetStatBComponent } from '@coreui/angular';

@Component({
  selector: 'docs-widgets-stats-b',
  templateUrl: './widgets-stats-b.component.html',
  imports: [RowComponent, ColComponent, WidgetStatBComponent, ProgressComponent]
})
export class WidgetsStatsBComponent {
  readonly value = signal<number>(75.9);
  readonly valuePercent = computed(() => `${this.value()}%`);
}
<c-row>
  <c-col md="12" xl="6">
    <c-widget-stat-b
      [title]="'Widget title'"
      class="mb-4"
      text="Lorem ipsum dolor sit amet enim."
      [value]="valuePercent()"
    >
      <br><br><br>
      <c-progress class="my-2" thin [value]="value()" color="success" />
    </c-widget-stat-b>
  </c-col>
  <c-col md="12" xl="6">
    <c-widget-stat-b
      #widgetStatB1inv="cWidgetStatB"
      [title]="'Widget title'"
      class="mb-4"
      color="primary"
      inverse
      text="Lorem ipsum dolor sit amet enim."
      [value]="valuePercent()"
    >
      <br><br><br>
      <c-progress [white]="widgetStatB1inv.inverse" class="my-2" thin [value]="value()" />
    </c-widget-stat-b>
  </c-col>
</c-row>

Widget Stats C

  • widgetIconTemplate
  • widgetProgressTemplate
import { Component, inject } from '@angular/core';
import {
  ColComponent,
  ProgressComponent,
  RowComponent,
  TemplateIdDirective,
  WidgetStatCComponent
} from '@coreui/angular';
import { IconDirective, IconSetService } from '@coreui/icons-angular';
import { cilChartPie } from '@coreui/icons';

@Component({
  selector: 'docs-widgets-stats-c',
  templateUrl: './widgets-stats-c.component.html',
  imports: [RowComponent, ColComponent, WidgetStatCComponent, TemplateIdDirective, IconDirective, ProgressComponent]
})
export class WidgetsStatsCComponent {
  public iconSet = inject(IconSetService);
  constructor() {
    this.iconSet.icons = {
      cilChartPie
    };
  }
}
<c-row>
  <c-col md="12" xl="6">
    <c-widget-stat-c
      [title]="'Widget Title'"
      class="mb-4"
      value="28%"
    >
      <ng-template cTemplateId="widgetIconTemplate">
        <svg cIcon height="36" name="cilChartPie"></svg>
      </ng-template>
      <ng-template cTemplateId="widgetProgressTemplate">
        <c-progress class="mt-3 mb-0" thin [value]="28" color="primary" />
      </ng-template>
    </c-widget-stat-c>
  </c-col>
  <c-col md="12" xl="6">
    <c-widget-stat-c
      [title]="'Widget Title'"
      class="mb-4"
      color="primary"
      inverse
      value="28%"
    >
      <ng-template cTemplateId="widgetIconTemplate">
        <svg cIcon height="36" name="cilChartPie"></svg>
      </ng-template>
      <ng-template cTemplateId="widgetProgressTemplate">
        <c-progress class="mt-3 mb-0" thin white [value]="28" />
      </ng-template>
    </c-widget-stat-c>
  </c-col>
</c-row>

Widget Stats D

import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, inject, input } from '@angular/core';
import { cibFacebook, cibLinkedin, cibTwitter } from '@coreui/icons';
import { ColComponent, RowComponent, WidgetStatDComponent } from '@coreui/angular';
import { ChartjsComponent } from '@coreui/angular-chartjs';
import { IconDirective } from '@coreui/icons-angular';
import { ChartOptions } from 'chart.js';

@Component({
  selector: 'docs-widgets-stats-d',
  templateUrl: './widgets-stats-d.component.html',
  standalone: true,
  changeDetection: ChangeDetectionStrategy.Eager,
  imports: [RowComponent, ColComponent, WidgetStatDComponent, IconDirective, ChartjsComponent]
})
export class WidgetsStatsDComponent implements AfterContentInit {
  readonly changeDetectorRef = inject(ChangeDetectorRef);

  icons = { cibFacebook, cibLinkedin, cibTwitter };

  readonly withCharts = input(true);

  chartOptions: ChartOptions = {
    elements: {
      line: {
        tension: 0.4
      },
      point: {
        radius: 0,
        hitRadius: 10,
        hoverRadius: 4,
        hoverBorderWidth: 3
      }
    },
    maintainAspectRatio: false,
    plugins: {
      legend: {
        display: false
      }
    },
    scales: {
      x: {
        display: false
      },
      y: {
        display: false
      }
    }
  };
  labels = ['January', 'February', 'March', 'April', 'May', 'June', 'July'];
  datasets = {
    borderWidth: 2,
    fill: true
  };
  colors = {
    backgroundColor: 'rgba(255,255,255,.1)',
    borderColor: 'rgba(255,255,255,.55)',
    pointHoverBackgroundColor: '#fff'
  };
  brandData = [
    {
      icon: this.icons.cibFacebook,
      values: [
        { title: 'friends', value: '89K' },
        { title: 'feeds', value: '459' }
      ],
      capBg: { '--cui-card-cap-bg': '#3b5998' },
      labels: [...this.labels],
      data: {
        labels: [...this.labels],
        datasets: [{ ...this.datasets, data: [65, 59, 84, 84, 51, 55, 40], label: 'Facebook', ...this.colors }]
      }
    },
    {
      icon: this.icons.cibTwitter,
      values: [
        { title: 'followers', value: '973k' },
        { title: 'tweets', value: '1.792' }
      ],
      capBg: { '--cui-card-cap-bg': '#00aced' },
      data: {
        labels: [...this.labels],
        datasets: [{ ...this.datasets, data: [1, 13, 9, 17, 34, 41, 38], label: 'Twitter', ...this.colors }]
      }
    },
    {
      icon: this.icons.cibLinkedin,
      values: [
        { title: 'contacts', value: '500' },
        { title: 'feeds', value: '1.292' }
      ],
      capBg: { '--cui-card-cap-bg': '#4875b4' },
      data: {
        labels: [...this.labels],
        datasets: [{ ...this.datasets, data: [78, 81, 80, 45, 34, 12, 40], label: 'LinkedIn', ...this.colors }]
      }
    }
  ];

  capStyle(value: string) {
    return !!value ? { '--cui-card-cap-bg': value } : {};
  }

  ngAfterContentInit(): void {
    this.changeDetectorRef.detectChanges();
  }
}
<c-row>
  @for (widget of brandData; track widget; let i = $index) {
    <c-col lg="6" md="12" xl="4">
      <c-widget-stat-d
        [style]="widget.capBg ?? null"
        [values]="widget.values"
        class="mb-4"
      >
        <svg [cIcon]="widget.icon" class="my-4 text-white" height="52"></svg>
        @if (withCharts()) {
          <c-chart
            #chart="cChart"
            [data]="widget.data"
            [options]="chartOptions"
            class="position-absolute w-100 h-100"
            type="line">
            {{ chart.id }}
          </c-chart>
        }
      </c-widget-stat-d>
    </c-col>
  }
</c-row>

Widget Stats E

import { Component, ChangeDetectionStrategy } from '@angular/core';
import { ChartjsComponent } from '@coreui/angular-chartjs';
import { ColComponent, RowComponent, WidgetStatEComponent } from '@coreui/angular';
import { ChartData, ChartOptions } from 'chart.js';

@Component({
  selector: 'docs-widgets-stats-e',
  templateUrl: './widgets-stats-e.component.html',
  standalone: true,
  changeDetection: ChangeDetectionStrategy.Eager,
  imports: [RowComponent, ColComponent, WidgetStatEComponent, ChartjsComponent]
})
export class WidgetsStatsEComponent {
  barOptions: ChartOptions = {
    maintainAspectRatio: false,
    plugins: {
      legend: {
        display: false
      }
    },
    scales: {
      x: {
        display: false
      },
      y: {
        display: false
      }
    }
  };

  lineOptions: ChartOptions = {
    maintainAspectRatio: false,
    elements: {
      line: {
        tension: 0.4
      },
      point: {
        radius: 0
      }
    },
    plugins: {
      legend: {
        display: false
      }
    },
    scales: {
      x: {
        display: false
      },
      y: {
        display: false
      }
    }
  };

  data: ChartData[] = [
    {
      labels: ['M', 'T', 'W', 'T', 'F', 'S', 'S', 'M', 'T', 'W', 'T', 'F', 'S', 'S', 'M'],
      datasets: [
        {
          backgroundColor: '#321fdb',
          borderColor: 'transparent',
          borderWidth: 1,
          data: [41, 78, 51, 66, 74, 42, 89, 97, 87, 84, 78, 88, 67, 45, 47]
        }
      ]
    },
    {
      labels: ['M', 'T', 'W', 'T', 'F', 'S', 'S', 'M', 'T', 'W', 'T', 'F', 'S', 'S', 'M'],
      datasets: [
        {
          backgroundColor: 'transparent',
          borderColor: '#321fdb',
          borderWidth: 2,
          data: [41, 78, 51, 66, 74, 42, 89, 97, 87, 84, 78, 88, 67, 45, 47],
          pointBackgroundColor: '#321fdb'
        }
      ]
    }
  ];
}
<c-row>
  <c-col xs="12" lg="6">
    <c-widget-stat-e
      [title]="'Widget Title'"
      [value]="'1,123'"
      class="mb-4"
    >
      <c-chart [data]="data[0]" [options]="barOptions" class="mx-auto" height="40" width="80" />
    </c-widget-stat-e>
  </c-col>
  <c-col xs="12" lg="6">
    <c-widget-stat-e
      [title]="'Widget Title'"
      [value]="'1,123'"
      class="mb-4"
    >
      <c-chart [data]="data[1]" [options]="lineOptions" type="line" class="mx-auto" height="40" width="80" />
    </c-widget-stat-e>
  </c-col>
</c-row>

Widget Stats F

  • widgetIconTemplate
  • widgetFooterTemplate
import { Component } from '@angular/core';
import { cilArrowRight, cilChartPie } from '@coreui/icons';
import { IconDirective } from '@coreui/icons-angular';
import { ColComponent, RowComponent, TemplateIdDirective, WidgetStatFComponent } from '@coreui/angular';

@Component({
  selector: 'docs-widgets-stats-f',
  templateUrl: './widgets-stats-f.component.html',
  imports: [RowComponent, ColComponent, WidgetStatFComponent, TemplateIdDirective, IconDirective]
})
export class WidgetsStatsFComponent {
  icons = { cilChartPie, cilArrowRight };
}
<c-row>
  <c-col lg="6" xs="12">
    <c-widget-stat-f
      [title]="'Widget Title'"
      class="mb-3"
      color="primary"
      padding
      value="89.9%"
    >
      <ng-template cTemplateId="widgetIconTemplate">
        <svg [cIcon]="icons.cilChartPie" size="xl" width="24"></svg>
      </ng-template>
    </c-widget-stat-f>
  </c-col>
  <c-col lg="6" xs="12">
    <c-widget-stat-f
      [title]="'Widget Title'"
      class="mb-3"
      color="warning"
      padding
      value="89.9%"
    >
      <ng-template cTemplateId="widgetIconTemplate">
        <svg [cIcon]="icons.cilChartPie" size="xl" width="24"></svg>
      </ng-template>
    </c-widget-stat-f>
  </c-col>
  <c-col lg="6" xs="12">
    <c-widget-stat-f
      [title]="'Widget Title'"
      class="mb-3"
      color="primary"
      padding
      value="89.9%"
    >
      <ng-template cTemplateId="widgetIconTemplate">
        <svg [cIcon]="icons.cilChartPie" size="xl" width="24"></svg>
      </ng-template>
      <ng-template cTemplateId="widgetFooterTemplate">
        <a class="font-weight-bold font-xs text-medium-emphasis"
           href="https://coreui.io/angular"
           target="_blank">
           <div class="d-flex align-items-center justify-content-between">
            <span>View more</span>
            <svg [cIcon]="icons.cilArrowRight" width="16"></svg>
          </div>
        </a>
      </ng-template>
    </c-widget-stat-f>
  </c-col>
  <c-col lg="6" xs="12">
    <c-widget-stat-f
      [title]="'Widget Title'"
      class="mb-3"
      color="warning"
      padding
      value="89.9%"
    >
      <ng-template cTemplateId="widgetIconTemplate">
        <svg [cIcon]="icons.cilChartPie" size="xl" width="24"></svg>
      </ng-template>
      <ng-template cTemplateId="widgetFooterTemplate">
        <a class="font-weight-bold font-xs text-medium-emphasis"
           href="https://coreui.io/angular"
           target="_blank">
          <div class="d-flex align-items-center justify-content-between">
            <span>View more</span>
            <svg [cIcon]="icons.cilArrowRight" width="16"></svg>
          </div>
        </a>
      </ng-template>
    </c-widget-stat-f>
  </c-col>
  <c-col lg="6" xs="12">
    <c-widget-stat-f
      [title]="'Widget Title'"
      class="mb-3"
      color="primary"
      value="89.9%"
    >
      <ng-template cTemplateId="widgetIconTemplate">
        <svg [cIcon]="icons.cilChartPie" size="xl" width="24"></svg>
      </ng-template>
    </c-widget-stat-f>
  </c-col>
  <c-col lg="6" xs="12">
    <c-widget-stat-f
      [title]="'Widget Title'"
      class="mb-3"
      color="warning"
      value="89.9%"
    >
      <ng-template cTemplateId="widgetIconTemplate">
        <svg [cIcon]="icons.cilChartPie" size="xl" width="24"></svg>
      </ng-template>
    </c-widget-stat-f>
  </c-col>
</c-row>

API reference

Widgets Module

import { DropdownModule, ProgressModule, SharedModule, WidgetsModule } from '@coreui/angular';
import { IconModule } from '@coreui/icons-angular';
import { ChartjsModule } from '@coreui/angular-chartjs';

@NgModule({
    imports: [
      DropdownModule,
      ProgressModule,
      SharedModule,
      WidgetsModule,
      IconModule,
      ChartjsModule
    ]
})
export class AppModule() { }

c-widget-stat-a

component

jsx
import { WidgetStatAComponent } from '@coreui/angular'
PropertyDefaultType
color-string

Sets the color context of the component to one of CoreUI’s themed colors.

textBgColor5.0.0+-string

Sets the component's color scheme to one of CoreUI themed colors, ensuring the text color contrast adheres to the WCAG 4.5:1 contrast ratio standard for accessibility. via TextBgColorDirective

textColor-string

Sets the text color context of the component to one of CoreUI’s themed colors. via TextColorDirective

title-string

Title of the widget to display

value-string

Value for your widget to display

c-widget-stat-b

component

jsx
import { WidgetStatBComponent } from '@coreui/angular'
PropertyDefaultType
color-string

Sets the color context of the component to one of CoreUI’s themed colors.

inversefalseboolean

Invert colors from their default dark shade.

text-string

Helper text for your widget.

textBgColor5.0.0+-string

Sets the component's color scheme to one of CoreUI themed colors, ensuring the text color contrast adheres to the WCAG 4.5:1 contrast ratio standard for accessibility. via TextBgColorDirective

textColor-string

Sets the text color context of the component to one of CoreUI’s themed colors. via TextColorDirective

title-string

Title of the widget to display

value-string

Value for your widget to display

c-widget-stat-c

component

jsx
import { WidgetStatCComponent } from '@coreui/angular'
PropertyDefaultType
color-string

Sets the color context of the component to one of CoreUI’s themed colors.

icon-string

Icon for your component.

inversefalseboolean

Invert colors from their default dark shade.

textBgColor5.0.0+-string

Sets the component's color scheme to one of CoreUI themed colors, ensuring the text color contrast adheres to the WCAG 4.5:1 contrast ratio standard for accessibility. via TextBgColorDirective

textColor-string

Sets the text color context of the component to one of CoreUI’s themed colors. via TextColorDirective

title-string

Title of the widget to display

value-string, number

Value for your widget to display

c-widget-stat-d

component

jsx
import { WidgetStatDComponent } from '@coreui/angular'
PropertyDefaultType
color-string

Sets the color context of the component to one of CoreUI’s themed colors.

textBgColor5.0.0+-string

Sets the component's color scheme to one of CoreUI themed colors, ensuring the text color contrast adheres to the WCAG 4.5:1 contrast ratio standard for accessibility. via TextBgColorDirective

textColor-string

Sets the text color context of the component to one of CoreUI’s themed colors. via TextColorDirective

values-WidgetStatDValue[]

Values and subtitles for your component.

c-widget-stat-e

component

jsx
import { WidgetStatEComponent } from '@coreui/angular'
PropertyDefaultType
color-string

Sets the color context of the component to one of CoreUI’s themed colors.

textBgColor5.0.0+-string

Sets the component's color scheme to one of CoreUI themed colors, ensuring the text color contrast adheres to the WCAG 4.5:1 contrast ratio standard for accessibility. via TextBgColorDirective

textColor-string

Sets the text color context of the component to one of CoreUI’s themed colors. via TextColorDirective

title-string

Title of the widget to display

value-string, number

Value for your widget to display

c-widget-stat-f

component

jsx
import { WidgetStatFComponent } from '@coreui/angular'
PropertyDefaultType
color-string

Sets the color context of the component to one of CoreUI’s themed colors.

Footer for your widget

icon-string

Icon for your widget

paddingfalseboolean

Set padding of your component.

textBgColor5.0.0+-string

Sets the component's color scheme to one of CoreUI themed colors, ensuring the text color contrast adheres to the WCAG 4.5:1 contrast ratio standard for accessibility. via TextBgColorDirective

textColor-string

Sets the text color context of the component to one of CoreUI’s themed colors. via TextColorDirective

title-string

Title of the widget to display

value-string, number

Value for your widget to display