Angular 円チャート
Ignite UI for Angular 円チャート (円グラフ) は、データセットのカテゴリ (部分) が合計 (全体) 値になる方法を示す部分対全体チャートです。カテゴリは、円グラフまたは円グラフのセクションとして描画されます。各セクション (円スライス) は基本データ値に比例する円弧の長さを持ちます。カテゴリは、分析中の合計値に対する値の割合に基づいて、100 または 100% の部分として他のカテゴリに比例して表示されます。
60 以上のリアルタイム Angular チャート を使用して、何百万ものデータ ポイントを描画し、視覚化を構築します。これは、あらゆるアプリケーション シナリオに対応する最も広範なチャート ライブラリです。
Angular 円チャートの例
データ項目を文字列と数値データでバインドすることで、IgxPieChartComponent
の円チャートが作成できます。これらのデータ値を足すと可視化率 100% になります。この例では部門ごとの予算支出の全体的な内訳を示しています。
export class EnergyGlobalDemandItem {
public constructor(init: Partial<EnergyGlobalDemandItem>) {
Object.assign(this, init);
}
public value: number;
public category: string;
public summary: string;
}
export class EnergyGlobalDemand extends Array<EnergyGlobalDemandItem> {
public constructor(items: Array<EnergyGlobalDemandItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new EnergyGlobalDemandItem(
{
value: 37,
category: `Cooling`,
summary: `Cooling 37%`
}),
new EnergyGlobalDemandItem(
{
value: 25,
category: `Residential`,
summary: `Residential 25%`
}),
new EnergyGlobalDemandItem(
{
value: 12,
category: `Heating`,
summary: `Heating 12%`
}),
new EnergyGlobalDemandItem(
{
value: 11,
category: `Lighting`,
summary: `Lighting 11%`
}),
new EnergyGlobalDemandItem(
{
value: 15,
category: `Other`,
summary: `Other 15%`
}),
];
super(...newItems.slice(0));
}
}
}
tsimport { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { CommonModule } from "@angular/common";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { IgxItemLegendModule, IgxPieChartModule } from 'igniteui-angular-charts';
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
CommonModule,
FormsModule,
IgxItemLegendModule,
IgxPieChartModule
],
providers: [],
schemas: []
})
export class AppModule {}
tsimport { AfterViewInit, Component, ViewChild, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { EnergyGlobalDemandItem, EnergyGlobalDemand } from './EnergyGlobalDemand';
import { IgxItemLegendComponent, IgxPieChartComponent } from 'igniteui-angular-charts';
@Component({
standalone: false,
selector: "app-root",
styleUrls: ["./app.component.scss"],
templateUrl: "./app.component.html",
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppComponent implements AfterViewInit
{
@ViewChild("legend", { static: true } )
private legend: IgxItemLegendComponent
@ViewChild("chart", { static: true } )
private chart: IgxPieChartComponent
private _energyGlobalDemand: EnergyGlobalDemand = null;
public get energyGlobalDemand(): EnergyGlobalDemand {
if (this._energyGlobalDemand == null)
{
this._energyGlobalDemand = new EnergyGlobalDemand();
}
return this._energyGlobalDemand;
}
public constructor(private _detector: ChangeDetectorRef)
{
}
public ngAfterViewInit(): void
{
}
}
ts<div class="container vertical sample">
<div class="legend-title">
Global Electricity Demand by Energy Use
</div>
<div class="legend">
<igx-item-legend
name="legend"
#legend
orientation="Horizontal">
</igx-item-legend>
</div>
<div class="container fill">
<igx-pie-chart
name="chart"
#chart
legendLabelMemberPath="category"
labelMemberPath="summary"
labelsPosition="BestFit"
valueMemberPath="value"
radiusFactor="0.7"
[dataSource]="energyGlobalDemand"
[legend]="legend">
</igx-pie-chart>
</div>
</div>
html/* styles are loaded the Shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
scss
このサンプルが気に入りましたか? 完全な Ignite UI for Angularツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
Angular 円チャートの推奨事項
円チャートは小さいデータ セットに適していて、一目で読みやすくなります。円チャートは、部分対全体の可視化の一種です。その他:
- 円
- ドーナツ (リング)
- ファンネル
- 積層型エリア
- 積層型 100% エリア (積層型パーセント エリア)
- 積層型棒
- 積層型 100% 棒 (積層型パーセント棒)
- ツリーマップ
- ウォーターフォール
Angular 円チャートは、データを解析するためのビューアー ツールを提供するインタラクティブ機能を含みます。
- 凡例
- スライスの分割
- スライスの選択
- チャート アニメーション
円チャートのベスト プラクティス:
- スライスまたはセグメントを、合計値または全体に対するパーセンテージ値として比較する。
- カテゴリのグループがどのようにより小さなセグメントに分割されるかを表示する。
- 小さい非階層データ セット (6 ~ 8 セグメント未満のデータ) を表示する。
- データ セグメントの合計が 100% になるようにする。
- データの順序を最大 (最高) から最小 (最低) に並べ替える。
- 12 時の位置から始めて時計回りに進む標準的なプレゼンテーション方法を使用する。
- カラー パレットがセグメント/スライスで識別できるようにする。
- データラベルを読みやすくするため、セグメントと凡例のどちらに配置するべきか検討する。
- より分かりやすい表現のために、円の代わりに棒またはリング チャートを選択する。
- 比較分析のために複数の円チャートを並べて配置しないようにする。
以下の場合に円チャートを使用しないでください。
- 経時変化を比較する場合 - 棒チャート、折れ線チャート、またはエリア チャートを使用してください。
- 正確なデータ比較が必要な場合 - 棒チャート、折れ線チャート、またはエリア チャートを使用してください。
- 6 セグメントまたは 8 セグメント (大量のデータ) がある場合 - データ ストーリーに適した棒チャート、折れ線チャート、またはエリア チャートを検討してください。
- 棒チャートで値の違いがわかりやすくなります。
Angular 円チャートの凡例
凡例は、各ポイントに関する情報を表示し、そのポイントの合計に対する割合を示します 凡例クリックを使用してポイントを縮小できます。
円チャート コンポーネントの隣に凡例を表示するには、ItemLegend を作成し、IgxLegendComponent
プロパティに割り当てます。legendLabelMemberPath
は、各円スライスの凡例項目を表示するために使用するデータ モデルのプロパティを指定します。
また、凡例項目の外観をカスタマイズするために legendItemTemplate
および legendItemBadgeTemplate
プロパティ、IgxItemLegendComponent
の複数のフォント プロパティも使用できます。
export class EnergyGlobalDemandItem {
public constructor(init: Partial<EnergyGlobalDemandItem>) {
Object.assign(this, init);
}
public value: number;
public category: string;
public summary: string;
}
export class EnergyGlobalDemand extends Array<EnergyGlobalDemandItem> {
public constructor(items: Array<EnergyGlobalDemandItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new EnergyGlobalDemandItem(
{
value: 37,
category: `Cooling`,
summary: `Cooling 37%`
}),
new EnergyGlobalDemandItem(
{
value: 25,
category: `Residential`,
summary: `Residential 25%`
}),
new EnergyGlobalDemandItem(
{
value: 12,
category: `Heating`,
summary: `Heating 12%`
}),
new EnergyGlobalDemandItem(
{
value: 11,
category: `Lighting`,
summary: `Lighting 11%`
}),
new EnergyGlobalDemandItem(
{
value: 15,
category: `Other`,
summary: `Other 15%`
}),
];
super(...newItems.slice(0));
}
}
}
tsimport { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { CommonModule } from "@angular/common";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { IgxItemLegendModule, IgxPieChartModule } from 'igniteui-angular-charts';
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
CommonModule,
FormsModule,
IgxItemLegendModule,
IgxPieChartModule
],
providers: [],
schemas: []
})
export class AppModule {}
tsimport { AfterViewInit, Component, ViewChild, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { EnergyGlobalDemandItem, EnergyGlobalDemand } from './EnergyGlobalDemand';
import { IgxItemLegendComponent, IgxPieChartComponent } from 'igniteui-angular-charts';
@Component({
standalone: false,
selector: "app-root",
styleUrls: ["./app.component.scss"],
templateUrl: "./app.component.html",
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppComponent implements AfterViewInit
{
@ViewChild("legend", { static: true } )
private legend: IgxItemLegendComponent
@ViewChild("chart", { static: true } )
private chart: IgxPieChartComponent
private _energyGlobalDemand: EnergyGlobalDemand = null;
public get energyGlobalDemand(): EnergyGlobalDemand {
if (this._energyGlobalDemand == null)
{
this._energyGlobalDemand = new EnergyGlobalDemand();
}
return this._energyGlobalDemand;
}
public constructor(private _detector: ChangeDetectorRef)
{
}
public ngAfterViewInit(): void
{
}
}
ts<div class="container vertical sample">
<div class="legend-title">
Global Electricity Demand by Energy Use
</div>
<div class="legend">
<igx-item-legend
name="legend"
#legend
orientation="Horizontal">
</igx-item-legend>
</div>
<div class="container fill">
<igx-pie-chart
name="chart"
#chart
valueMemberPath="value"
labelMemberPath="summary"
labelsPosition="OutsideEnd"
legendLabelMemberPath="category"
outlines="white"
radiusFactor="0.7"
labelExtent="30"
[dataSource]="energyGlobalDemand"
[legend]="legend">
</igx-pie-chart>
</div>
</div>
html/* styles are loaded the Shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
scss
Angular 円チャートその他の分類項目
円チャート コンポーネントの基本データに、小さい値を含む多くの項目が含まれる場合があります。この場合、Others カテゴリは、単一スライスへの複数のデータ値の自動集計を許可します。
以下のサンプルは、othersCategoryThreshold
を 2 に設定、othersCategoryType
は Number に設定されています。したがって、2 以下の値を含む項目は、Others カテゴリに割り当てられます。
othersCategoryType
を Percent に設定すると、othersCategoryThreshold
は値ではなくパーセンテージとして解釈されます。つまり、値がすべての項目の値の合計の 2% 未満である項目は、Others カテゴリに割り当てられます。使用しているアプリケーションに最も適切な othersCategoryType
を使用できます。
export class EnergyGlobalDemandItem {
public constructor(init: Partial<EnergyGlobalDemandItem>) {
Object.assign(this, init);
}
public value: number;
public category: string;
public summary: string;
}
export class EnergyGlobalDemand extends Array<EnergyGlobalDemandItem> {
public constructor(items: Array<EnergyGlobalDemandItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new EnergyGlobalDemandItem(
{
value: 37,
category: `Cooling`,
summary: `Cooling 37%`
}),
new EnergyGlobalDemandItem(
{
value: 25,
category: `Residential`,
summary: `Residential 25%`
}),
new EnergyGlobalDemandItem(
{
value: 12,
category: `Heating`,
summary: `Heating 12%`
}),
new EnergyGlobalDemandItem(
{
value: 11,
category: `Lighting`,
summary: `Lighting 11%`
}),
new EnergyGlobalDemandItem(
{
value: 15,
category: `Other`,
summary: `Other 15%`
}),
];
super(...newItems.slice(0));
}
}
}
tsimport { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { CommonModule } from "@angular/common";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { IgxItemLegendModule, IgxPieChartModule } from 'igniteui-angular-charts';
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
CommonModule,
FormsModule,
IgxItemLegendModule,
IgxPieChartModule
],
providers: [],
schemas: []
})
export class AppModule {}
tsimport { AfterViewInit, Component, ViewChild, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { EnergyGlobalDemandItem, EnergyGlobalDemand } from './EnergyGlobalDemand';
import { IgxItemLegendComponent, IgxPieChartComponent } from 'igniteui-angular-charts';
@Component({
standalone: false,
selector: "app-root",
styleUrls: ["./app.component.scss"],
templateUrl: "./app.component.html",
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppComponent implements AfterViewInit
{
@ViewChild("legend", { static: true } )
private legend: IgxItemLegendComponent
@ViewChild("chart", { static: true } )
private chart: IgxPieChartComponent
private _energyGlobalDemand: EnergyGlobalDemand = null;
public get energyGlobalDemand(): EnergyGlobalDemand {
if (this._energyGlobalDemand == null)
{
this._energyGlobalDemand = new EnergyGlobalDemand();
}
return this._energyGlobalDemand;
}
public constructor(private _detector: ChangeDetectorRef)
{
}
public ngAfterViewInit(): void
{
}
}
ts<div class="container vertical sample">
<div class="legend-title">
Global Electricity Demand by Energy Use
</div>
<div class="legend">
<igx-item-legend
name="legend"
#legend
orientation="Horizontal">
</igx-item-legend>
</div>
<div class="container fill">
<igx-pie-chart
name="chart"
#chart
labelMemberPath="summary"
labelsPosition="OutsideEnd"
labelExtent="30"
valueMemberPath="value"
outlines="white"
othersCategoryThreshold="10"
othersCategoryType="Number"
othersCategoryText="Others"
radiusFactor="0.7"
legendLabelMemberPath="category"
[dataSource]="energyGlobalDemand"
[legend]="legend">
</igx-pie-chart>
</div>
</div>
html/* styles are loaded the Shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
scss
Angular 円チャートの展開
円チャート コンポーネントは個々の円スライスの選択と展開だけでなく、選択状態を変更しカスタム ロジックを実装することを可能にする SliceClick
イベントをコンポーネントサポートします。
import { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { CommonModule } from "@angular/common";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { IgxPieChartModule, IgxLegendModule } from "igniteui-angular-charts";
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
CommonModule,
FormsModule,
IgxPieChartModule,
IgxLegendModule
],
providers: [],
schemas: []
})
export class AppModule {}
tsimport { AfterViewInit, Component, ViewChild } from "@angular/core";
import { IgxPieChartComponent } from "igniteui-angular-charts";
@Component({
standalone: false,
selector: "app-root",
styleUrls: ["./app.component.scss"],
templateUrl: "./app.component.html"
})
export class AppComponent implements AfterViewInit {
public data: any;
@ViewChild("chart", { static: true })
public chart: IgxPieChartComponent;
constructor() {
this.data = [
{ MarketShare: 37, Company: "Cooling", Summary: "Cooling 37%" },
{ MarketShare: 25, Company: "Residential", Summary: "Residential 25%" },
{ MarketShare: 12, Company: "Heating", Summary: "Heating 12%" },
{ MarketShare: 8, Company: "Lighting", Summary: "Lighting 8%" },
{ MarketShare: 18, Company: "Other", Summary: "Other 18%" }
];
}
public pieSliceClickEvent(e: any): void {
e.args.isExploded = !e.args.isExploded;
}
public ngAfterViewInit(): void {
this.chart.explodedSlices.add(3);
}
}
ts<div class="container vertical">
<div class="options vertical">
<span id="legendTitle">Global Electricity Demand by Energy Use</span>
<igx-item-legend #legend></igx-item-legend>
</div>
<div class="container">
<igx-pie-chart #chart
height="100%"
width="100%"
[dataSource]="data"
[legend]="legend"
labelMemberPath="Summary"
legendLabelMemberPath="Company"
valueMemberPath="MarketShare"
(sliceClick)="pieSliceClickEvent($event)"
labelsPosition="OutsideEnd"
labelExtent="30">
</igx-pie-chart>
</div>
html/* styles are loaded the Shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
scss
Angular 円チャートの選択
デフォルトで、円チャートはマウス クリックによるスライス選択をサポートします。選択されたスライスは、selectedItems
プロパティで取得します。選択したスライスがハイライト表示されます。
円チャートのモードは selectionMode
プロパティで設定します。デフォルト値は Single
です。選択機能を無効化するためにはプロパティを Manual
に設定します。
円チャート コンポーネントは、選択モードを 3 つコンポーネントサポートします。
- Single - single モードに設定すると、一度に 1 つのスライスのみ選択します。他のスライスを選択すると、最初に選択したスライスは選択解除され、新しいスライスが選択されます。
- Multiple - Multiple モードに設定すると、一度に複数のスライスを選択します。スライスをクリックするとスライスが選択され、他のスライスをクリックすると、最初のスライスも、新しくクリックしたスライスも選択されます。
- 手動 - Manual モードに設定すると、選択は無効化されます。
円チャート コンポーネントには、選択機能に関連する 4 つのイベントがあります。
- SelectedItemChanging
- SelectedItemChanged
- SelectedItemsChanging
- SelectedItemsChanged
「Changing」で終わるイベントはキャンセル可能なイベントです。すなわち、イベント引数プロパティ Cancel
を true に設定することで、スライスの選択を停止します。True に設定すると、関連付けられたプロパティは更新されず、その結果スライスは選択されません。この設定はたとえば、スライスのデータによって一定のスライスの選択を無効化する場合に使用します。
「その他」スライスをクリックすると、IgxPieSliceOthersContext
オブジェクトが返されます。オブジェクトは、「その他」スライスに含まれるデータ項目のリストがあります。
import { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { CommonModule } from "@angular/common";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { IgxPieChartModule, IgxLegendModule, IgxItemLegendModule } from "igniteui-angular-charts";
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
CommonModule,
FormsModule,
IgxPieChartModule,
IgxLegendModule,
IgxItemLegendModule
],
providers: [],
schemas: []
})
export class AppModule {}
tsimport { AfterViewInit, Component, ViewChild } from "@angular/core";
import { IgxPieChartComponent } from "igniteui-angular-charts";
@Component({
standalone: false,
selector: "app-root",
styleUrls: ["./app.component.scss"],
templateUrl: "./app.component.html"
})
export class AppComponent implements AfterViewInit {
public selectionType: string;
public data: any;
@ViewChild("chart", { static: true })
public chart: IgxPieChartComponent;
constructor() {
this.data = [
{ MarketShare: 37, Company: "Cooling", Summary: "Cooling 37%" },
{ MarketShare: 25, Company: "Residential", Summary: "Residential 25%" },
{ MarketShare: 12, Company: "Heating", Summary: "Heating 12%" },
{ MarketShare: 8, Company: "Lighting", Summary: "Lighting 8%" },
{ MarketShare: 18, Company: "Other", Summary: "Other 18%" }
];
this.selectionType = "Single";
}
public ngAfterViewInit(): void {
this.chart.selectedItem = this.data[3];
}
}
ts<div class="container vertical">
<div class="options vertical">
<label id="legendTitle">Global Electricity Demand by Energy Use</label>
<igx-item-legend #legend></igx-item-legend>
</div>
<div class="container">
<igx-pie-chart #chart
height="100%"
width="100%"
[dataSource]="data"
[legend]="legend"
valueMemberPath="MarketShare"
labelMemberPath="Summary"
legendLabelMemberPath="Company"
[selectionMode]="selectionType"
selectedSliceStroke = "white"
selectedSliceFill= "rgb(143,143,143)"
selectedSliceOpacity =1.0
selectedSliceStrokeThickness=2
labelsPosition="OutsideEnd"
labelExtent="30">
</igx-pie-chart>
</div>
</div>
html/* styles are loaded the Shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
scss
Angular 円チャートのアニメーション
チャートの半径をスケールする radiusFactor
プロパティを設定して円チャートをすばやくアニメーション化できます。startAngle
プロパティを設定してチャートが回転する間、チャートの角度が増加し続けるようにします。
以下のコードでは、radiusFactor がチャートをサイズの 0.25% 増加し、startAngle がチャートを 1 度回転しています。radiusFactor と startAngle が最大値に達すると、アニメーション フラグをリセットし、間隔をクリアしてアニメーションを停止します。
import { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { CommonModule } from "@angular/common";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { IgxPieChartModule, IgxLegendModule } from "igniteui-angular-charts";
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
CommonModule,
FormsModule,
IgxPieChartModule,
IgxLegendModule
],
providers: [],
schemas: []
})
export class AppModule {}
tsimport { AfterViewInit, Component, ElementRef, NgZone, ViewChild } from "@angular/core";
import { IgxPieChartComponent } from "igniteui-angular-charts";
@Component({
standalone: false,
selector: "app-root",
styleUrls: ["./app.component.scss"],
templateUrl: "./app.component.html"
})
export class AppComponent implements AfterViewInit {
public data: any;
@ViewChild("chart", { static: true })
public chart: IgxPieChartComponent;
public animateChart: string = "Pause Animation";
private _refreshInterval: number = 10;
private _interval: number = -1;
private isTimerStarted: boolean = false;
constructor(private _zone: NgZone) {
this.data = [
{ MarketShare: 37, Company: "Cooling", Summary: "Cooling 37%" },
{ MarketShare: 25, Company: "Residential", Summary: "Residential 25%" },
{ MarketShare: 12, Company: "Heating", Summary: "Heating 12%" },
{ MarketShare: 8, Company: "Lighting", Summary: "Lighting 8%" },
{ MarketShare: 18, Company: "Other", Summary: "Other 18%" }
];
}
public onClicked() {
if (!this.isTimerStarted) {
this.animateChart = "Start Animation";
this.isTimerStarted = true;
window.setTimeout(() => this.tick(), 16);
} else {
this.isTimerStarted = false;
this.animateChart = "Pause Animation";
}
}
public get refreshInterval(): number {
return this._refreshInterval;
}
public set refreshInterval(v: number) {
this._refreshInterval = v;
this.setupInterval();
}
public ngAfterViewInit(): void {
this.setupInterval();
}
private setupInterval(): void {
if (this._interval >= 0) {
this._zone.runOutsideAngular(() => {
window.clearInterval(this._interval);
});
this._interval = -1;
}
this._zone.runOutsideAngular(() => {
this._interval = window.setInterval(() => this.tick(),
this.refreshInterval);
});
}
private tick(): void {
if (!this.isTimerStarted) {
this.chart.radiusFactor += 0.0025;
this.chart.startAngle++;
if (this.chart.startAngle >= 360) {
this.chart.startAngle = 0;
}
if (this.chart.radiusFactor > 1.0) {
this.chart.radiusFactor = 0.1;
}
}
}
}
ts<div class="container vertical">
<div class="options horizontal">
<button class="button" (click)="onClicked()" >
<label>{{animateChart}}</label>
</button>
</div>
<div class="container">
<igx-pie-chart #chart height="100%"
width="100%"
[dataSource]="data"
valueMemberPath="MarketShare"
labelMemberPath="Summary"
labelsPosition="InsideEnd"
startAngle = 0
labelExtent = 0.7
radiusFactor = 0.1>
</igx-pie-chart>
</div>
</div>
html/* styles are loaded the Shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
scss
Angular 円チャートのスタイル設定
円チャートを作成したら、次に示すように、チャートのスライスの色を変更するなど、スタイルをさらにカスタマイズすることができます。
export class EnergyGlobalDemandItem {
public constructor(init: Partial<EnergyGlobalDemandItem>) {
Object.assign(this, init);
}
public value: number;
public category: string;
public summary: string;
}
export class EnergyGlobalDemand extends Array<EnergyGlobalDemandItem> {
public constructor(items: Array<EnergyGlobalDemandItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new EnergyGlobalDemandItem(
{
value: 37,
category: `Cooling`,
summary: `Cooling 37%`
}),
new EnergyGlobalDemandItem(
{
value: 25,
category: `Residential`,
summary: `Residential 25%`
}),
new EnergyGlobalDemandItem(
{
value: 12,
category: `Heating`,
summary: `Heating 12%`
}),
new EnergyGlobalDemandItem(
{
value: 11,
category: `Lighting`,
summary: `Lighting 11%`
}),
new EnergyGlobalDemandItem(
{
value: 15,
category: `Other`,
summary: `Other 15%`
}),
];
super(...newItems.slice(0));
}
}
}
tsimport { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { CommonModule } from "@angular/common";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { IgxPieChartModule, IgxItemLegendModule } from 'igniteui-angular-charts';
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
CommonModule,
FormsModule,
IgxPieChartModule,
IgxItemLegendModule
],
providers: [],
schemas: []
})
export class AppModule {}
tsimport { AfterViewInit, Component, ViewChild, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { EnergyGlobalDemandItem, EnergyGlobalDemand } from './EnergyGlobalDemand';
import { IgxItemLegendComponent, IgxPieChartComponent } from 'igniteui-angular-charts';
@Component({
standalone: false,
selector: "app-root",
styleUrls: ["./app.component.scss"],
templateUrl: "./app.component.html",
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppComponent implements AfterViewInit
{
@ViewChild("legend", { static: true } )
private legend: IgxItemLegendComponent
@ViewChild("chart", { static: true } )
private chart: IgxPieChartComponent
private _energyGlobalDemand: EnergyGlobalDemand = null;
public get energyGlobalDemand(): EnergyGlobalDemand {
if (this._energyGlobalDemand == null)
{
this._energyGlobalDemand = new EnergyGlobalDemand();
}
return this._energyGlobalDemand;
}
public constructor(private _detector: ChangeDetectorRef)
{
}
public ngAfterViewInit(): void
{
}
}
ts<div class="container vertical sample">
<div class="legend-title">
Global Electricity Demand by Energy Use
</div>
<div class="legend">
<igx-item-legend
name="legend"
#legend
orientation="Horizontal">
</igx-item-legend>
</div>
<div class="container fill">
<igx-pie-chart
name="chart"
#chart
legendLabelMemberPath="category"
valueMemberPath="value"
labelMemberPath="summary"
labelsPosition="OutsideEnd"
labelExtent="30"
brushes="rgba(247, 210, 98, 1) rgba(168, 168, 183, 1) rgba(224, 81, 169, 1) rgba(248, 161, 95, 1) rgba(115, 86, 86, 1)"
outlines="white"
radiusFactor="0.7"
startAngle="0"
[dataSource]="energyGlobalDemand"
[legend]="legend">
</igx-pie-chart>
</div>
</div>
html/* styles are loaded the Shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
scss
Angular ラジアル円チャート
ラジアル円チャートはラジアル チャートのグループに属し、チャートの中心からデータ ポイントの位置に向かって伸びる円スライスを使用します。このチャート タイプは、複数の一連のデータ ポイントを分類するという概念を採用しており、データ ポイントを水平線に沿って引き伸ばすのではなく、円形の軸に沿ってラップします。
export class FootballPlayerStatsItem {
public constructor(init: Partial<FootballPlayerStatsItem>) {
Object.assign(this, init);
}
public attribute: string;
public ronaldo: number;
public messi: number;
}
export class FootballPlayerStats extends Array<FootballPlayerStatsItem> {
public constructor(items: Array<FootballPlayerStatsItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new FootballPlayerStatsItem(
{
attribute: `Dribbling`,
ronaldo: 8,
messi: 10
}),
new FootballPlayerStatsItem(
{
attribute: `Passing`,
ronaldo: 8,
messi: 10
}),
new FootballPlayerStatsItem(
{
attribute: `Finishing`,
ronaldo: 10,
messi: 10
}),
new FootballPlayerStatsItem(
{
attribute: `Free Kicks`,
ronaldo: 8,
messi: 9
}),
new FootballPlayerStatsItem(
{
attribute: `Penalties`,
ronaldo: 9,
messi: 7
}),
new FootballPlayerStatsItem(
{
attribute: `Physical`,
ronaldo: 10,
messi: 7
}),
new FootballPlayerStatsItem(
{
attribute: `Team Play`,
ronaldo: 7,
messi: 9
}),
new FootballPlayerStatsItem(
{
attribute: `Heading`,
ronaldo: 9,
messi: 6
}),
];
super(...newItems.slice(0));
}
}
}
tsimport { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { CommonModule } from "@angular/common";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { IgxLegendModule, IgxDataChartCoreModule, IgxDataChartRadialModule, IgxDataChartRadialCoreModule, IgxDataChartInteractivityModule, IgxDataChartAnnotationModule } from 'igniteui-angular-charts';
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
CommonModule,
FormsModule,
IgxLegendModule,
IgxDataChartCoreModule,
IgxDataChartRadialModule,
IgxDataChartRadialCoreModule,
IgxDataChartInteractivityModule,
IgxDataChartAnnotationModule
],
providers: [],
schemas: []
})
export class AppModule {}
tsimport { AfterViewInit, Component, ViewChild, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { FootballPlayerStatsItem, FootballPlayerStats } from './FootballPlayerStats';
import { IgxLegendComponent, IgxDataChartComponent, IgxCategoryAngleAxisComponent, IgxNumericRadiusAxisComponent, IgxRadialPieSeriesComponent, IgxDataToolTipLayerComponent } from 'igniteui-angular-charts';
@Component({
standalone: false,
selector: "app-root",
styleUrls: ["./app.component.scss"],
templateUrl: "./app.component.html",
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppComponent implements AfterViewInit
{
@ViewChild("legend", { static: true } )
private legend: IgxLegendComponent
@ViewChild("chart", { static: true } )
private chart: IgxDataChartComponent
@ViewChild("angleAxis", { static: true } )
private angleAxis: IgxCategoryAngleAxisComponent
@ViewChild("radiusAxis", { static: true } )
private radiusAxis: IgxNumericRadiusAxisComponent
@ViewChild("radialPieSeries1", { static: true } )
private radialPieSeries1: IgxRadialPieSeriesComponent
@ViewChild("radialPieSeries2", { static: true } )
private radialPieSeries2: IgxRadialPieSeriesComponent
@ViewChild("dataToolTipLayer", { static: true } )
private dataToolTipLayer: IgxDataToolTipLayerComponent
private _footballPlayerStats: FootballPlayerStats = null;
public get footballPlayerStats(): FootballPlayerStats {
if (this._footballPlayerStats == null)
{
this._footballPlayerStats = new FootballPlayerStats();
}
return this._footballPlayerStats;
}
public constructor(private _detector: ChangeDetectorRef)
{
}
public ngAfterViewInit(): void
{
}
}
ts<div class="container vertical sample">
<div class="legend-title">
Ronaldo vs Messi Player Stats
</div>
<div class="legend">
<igx-legend
name="legend"
#legend
orientation="Horizontal">
</igx-legend>
</div>
<div class="container fill">
<igx-data-chart
name="chart"
#chart
[legend]="legend"
isHorizontalZoomEnabled="false"
isVerticalZoomEnabled="false">
<igx-category-angle-axis
name="angleAxis"
#angleAxis
[dataSource]="footballPlayerStats"
label="attribute">
</igx-category-angle-axis>
<igx-numeric-radius-axis
name="radiusAxis"
#radiusAxis
innerRadiusExtentScale="0.1"
interval="2"
minimumValue="0"
maximumValue="10">
</igx-numeric-radius-axis>
<igx-radial-pie-series
name="RadialPieSeries1"
#radialPieSeries1
[dataSource]="footballPlayerStats"
[angleAxis]="angleAxis"
[valueAxis]="radiusAxis"
valueMemberPath="ronaldo"
showDefaultTooltip="false"
areaFillOpacity="0.8"
thickness="3"
title="Ronaldo">
</igx-radial-pie-series>
<igx-radial-pie-series
name="RadialPieSeries2"
#radialPieSeries2
[dataSource]="footballPlayerStats"
[angleAxis]="angleAxis"
[valueAxis]="radiusAxis"
valueMemberPath="messi"
showDefaultTooltip="false"
areaFillOpacity="0.8"
thickness="3"
title="Messi">
</igx-radial-pie-series>
<igx-data-tool-tip-layer
name="dataToolTipLayer"
#dataToolTipLayer>
</igx-data-tool-tip-layer>
</igx-data-chart>
</div>
</div>
html/* styles are loaded the Shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/
scss
その他のリソース
API リファレンス
以下のテーブルは、上記のセクションで説明した API メンバーをリストします。
legendItemBadgeTemplate
legendItemTemplate
legendLabelMemberPath
othersCategoryThreshold
othersCategoryType
selectionMode
チャート タイプ | コントロール名 | API メンバー |
---|---|---|
円チャート | IgxPieChartComponent |
PieChart |
ラジアル円チャート | IgxDataChartComponent |
IgxRadialPieSeriesComponent |