Icicle from Drilldown in Angular

Using ApexCharts with Angular

This Icicle from Drilldown example wires ApexCharts into Angular through the ng-apexcharts component.

Install it with npm install ng-apexcharts apexcharts, then mount the chart with <apx-chart [series]="series" [chart]="chart"></apx-chart>.

Angular charts guide

This demo uses imperative chart updates. The generated code is a faithful Angular translation: open it in CodeSandbox to run and tweak.

import { Component, AfterViewInit, OnDestroy, ViewChild } from '@angular/core';
import {
  ChartComponent,
  ApexAxisChartSeries,
  ApexNonAxisChartSeries,
  ApexChart,
  ApexXAxis,
  ApexYAxis,
  ApexTitleSubtitle,
  ApexDataLabels,
  ApexStroke,
  ApexFill,
  ApexLegend,
  ApexTooltip,
  ApexMarkers,
  ApexPlotOptions,
  ApexResponsive,
  ApexGrid,
  ApexAnnotations,
  ApexStates,
  ApexTheme,
  NgApexchartsModule,
} from 'ng-apexcharts';

export type ChartOptions = {
  series?: ApexAxisChartSeries | ApexNonAxisChartSeries;
  chart?: ApexChart;
  xaxis?: ApexXAxis;
  yaxis?: ApexYAxis | ApexYAxis[];
  title?: ApexTitleSubtitle;
  subtitle?: ApexTitleSubtitle;
  dataLabels?: ApexDataLabels;
  stroke?: ApexStroke;
  fill?: ApexFill;
  legend?: ApexLegend;
  tooltip?: ApexTooltip;
  markers?: ApexMarkers;
  plotOptions?: ApexPlotOptions;
  responsive?: ApexResponsive[];
  grid?: ApexGrid;
  annotations?: ApexAnnotations;
  states?: ApexStates;
  theme?: ApexTheme;
  colors?: string[];
  labels?: any;
};

@Component({
  selector: 'app-chart',
  standalone: true,
  imports: [NgApexchartsModule],
  templateUrl: './chart.component.html',
})
export class AppChart implements AfterViewInit, OnDestroy {
  @ViewChild('chart') chart!: ChartComponent;
  private channelColors: any = ['#0EA5E9', '#14B8A6', '#F59E0B'];

  private searchColors: any = ['#0369A1', '#0284C7', '#38BDF8'];

  private socialColors: any = ['#0F766E', '#14B8A6', '#5EEAD4'];

  public chartOptions: Partial<ChartOptions> = {
          series: [
            {
              data: [
                { x: 'Search', y: 790, drilldown: 'search' },
                { x: 'Social', y: 360, drilldown: 'social' },
                { x: 'Direct', y: 240 },
              ],
            },
          ],
          chart: {
            type: 'icicle',
            height: 380,
          },
          colors: this.channelColors,
          // A legend is off by default (every cell is labelled already), but this tree
          // has several roots, so the palette lines up with it exactly.
          legend: {
            show: true,
            position: 'bottom',
          },
          title: {
            text: 'Signups by acquisition channel',
            align: 'left',
          },
          subtitle: {
            text: 'The same series + drilldown.series config as a drilldown chart, shown whole.',
            align: 'left',
          },
          plotOptions: {
            icicle: {
              direction: 'right',
              borderRadius: 2,
            },
          },
          stroke: {
            width: 1,
            colors: ['#fff'],
          },
          drilldown: {
            series: [
              {
                id: 'search',
                name: 'Search',
                colors: this.searchColors,
                data: [
                  { x: 'Organic', y: 420 },
                  { x: 'Paid', y: 260 },
                  { x: 'Brand', y: 110 },
                ],
              },
              {
                id: 'social',
                name: 'Social',
                colors: this.socialColors,
                data: [
                  { x: 'Video', y: 180 },
                  { x: 'Posts', y: 120 },
                  { x: 'Communities', y: 60 },
                ],
              },
            ],
          },
        };
  ngAfterViewInit() {
    (window as any).ApexCharts.setLicense('APEX-eyJleHBpcnlEYXRlIjoiMjEyNi0wNy0wNCIsImlzc3VlRGF0ZSI6IjIwMjYtMDctMjgiLCJwbGFuIjoicHJlbWl1bSIsImRvbWFpbnMiOlsiYXBleGNoYXJ0cy5jb20iLCIxMjcuMC4wLjEiLCJsb2NhbGhvc3QiXSwic2lnIjoieVBmb1VCc0Z3TU9ZdUEyaEZkR0I2Y1FtZ0JITUtXcVdJSjB2NVRESXRZbFR3eDJMUmh6R2x0RUc3VXJ4X0s3b25ZMWRZb2Z2VGItN01ydFYyNDVyOWcifQ==');
  }

  ngOnDestroy() {
    // no cleanup needed
  }
}