React 円チャート
Ignite UI for React 円チャート (円グラフ) は、データセットのカテゴリ (部分) が合計 (全体) 値になる方法を示す部分対全体チャートです。カテゴリは、円グラフまたは円グラフのセクションとして描画されます。各セクション (円スライス) は基本データ値に比例する円弧の長さを持ちます。カテゴリは、分析中の合計値に対する値の割合に基づいて、100 または 100% の部分として他のカテゴリに比例して表示されます。
React 円チャートの例
データ項目を文字列と数値データでバインドすることで、IgrPieChart
の円チャートが作成できます。これらのデータ値を足すと可視化率 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 React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrItemLegendModule, IgrPieChartModule } from "@infragistics/igniteui-react-charts";
import { IgrItemLegend, IgrPieChart } from "@infragistics/igniteui-react-charts";
import { EnergyGlobalDemandItem, EnergyGlobalDemand } from './EnergyGlobalDemand';
const mods: any[] = [
IgrItemLegendModule,
IgrPieChartModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private legend: IgrItemLegend
private legendRef(r: IgrItemLegend) {
this.legend = r;
this.setState({});
}
private chart: IgrPieChart
private chartRef(r: IgrPieChart) {
this.chart = r;
this.setState({});
}
constructor(props: any) {
super(props);
this.legendRef = this.legendRef.bind(this);
this.chartRef = this.chartRef.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="legend-title">
Global Electricity Demand by Energy Use
</div>
<div className="legend">
<IgrItemLegend
ref={this.legendRef}
orientation="Horizontal">
</IgrItemLegend>
</div>
<div className="container fill">
<IgrPieChart
ref={this.chartRef}
legendLabelMemberPath="category"
labelMemberPath="summary"
labelsPosition="BestFit"
valueMemberPath="value"
radiusFactor="0.7"
dataSource={this.energyGlobalDemand}
legend={this.legend}>
</IgrPieChart>
</div>
</div>
);
}
private _energyGlobalDemand: EnergyGlobalDemand = null;
public get energyGlobalDemand(): EnergyGlobalDemand {
if (this._energyGlobalDemand == null)
{
this._energyGlobalDemand = new EnergyGlobalDemand();
}
return this._energyGlobalDemand;
}
}
// rendering above component in the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);
tsx/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
css
このサンプルが気に入りましたか? 完全な Ignite UI for Reactツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
React 円チャートの推奨事項
円チャートは小さいデータ セットに適していて、一目で読みやすくなります。円チャートは、部分対全体の可視化の一種です。その他:
- 円
- ドーナツ (リング)
- ファンネル
- 積層型エリア
- 積層型 100% エリア (積層型パーセント エリア)
- 積層型棒
- 積層型 100% 棒 (積層型パーセント棒)
- ツリーマップ
- ウォーターフォール
React 円チャートは、データを解析するためのビューアー ツールを提供するインタラクティブ機能を含みます。
- 凡例
- スライスの分割
- スライスの選択
- チャート アニメーション
円チャートのベスト プラクティス:
- スライスまたはセグメントを、合計値または全体に対するパーセンテージ値として比較する。
- カテゴリのグループがどのようにより小さなセグメントに分割されるかを表示する。
- 小さい非階層データ セット (6 ~ 8 セグメント未満のデータ) を表示する。
- データ セグメントの合計が 100% になるようにする。
- データの順序を最大 (最高) から最小 (最低) に並べ替える。
- 12 時の位置から始めて時計回りに進む標準的なプレゼンテーション方法を使用する。
- カラー パレットがセグメント/スライスで識別できるようにする。
- データラベルを読みやすくするため、セグメントと凡例のどちらに配置するべきか検討する。
- より分かりやすい表現のために、円の代わりに棒またはリング チャートを選択する。
- 比較分析のために複数の円チャートを並べて配置しないようにする。
以下の場合に円チャートを使用しないでください。
- 経時変化を比較する場合 - 棒チャート、折れ線チャート、またはエリア チャートを使用してください。
- 正確なデータ比較が必要な場合 - 棒チャート、折れ線チャート、またはエリア チャートを使用してください。
- 6 セグメントまたは 8 セグメント (大量のデータ) がある場合 - データ ストーリーに適した棒チャート、折れ線チャート、またはエリア チャートを検討してください。
- 棒チャートで値の違いがわかりやすくなります。
React 円チャートの凡例
凡例は、各ポイントに関する情報を表示し、そのポイントの合計に対する割合を示します 凡例クリックを使用してポイントを縮小できます。
円チャート コンポーネントの隣に凡例を表示するには、ItemLegend を作成し、IgrLegend
プロパティに割り当てます。legendLabelMemberPath
は、各円スライスの凡例項目を表示するために使用するデータ モデルのプロパティを指定します。
また、凡例項目の外観をカスタマイズするために legendItemTemplate
および legendItemBadgeTemplate
プロパティ、IgrItemLegend
の複数のフォント プロパティも使用できます。
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 React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrItemLegendModule, IgrPieChartModule } from "@infragistics/igniteui-react-charts";
import { IgrItemLegend, IgrPieChart } from "@infragistics/igniteui-react-charts";
import { EnergyGlobalDemandItem, EnergyGlobalDemand } from './EnergyGlobalDemand';
const mods: any[] = [
IgrItemLegendModule,
IgrPieChartModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private legend: IgrItemLegend
private legendRef(r: IgrItemLegend) {
this.legend = r;
this.setState({});
}
private chart: IgrPieChart
private chartRef(r: IgrPieChart) {
this.chart = r;
this.setState({});
}
constructor(props: any) {
super(props);
this.legendRef = this.legendRef.bind(this);
this.chartRef = this.chartRef.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="legend-title">
Global Electricity Demand by Energy Use
</div>
<div className="legend">
<IgrItemLegend
ref={this.legendRef}
orientation="Horizontal">
</IgrItemLegend>
</div>
<div className="container fill">
<IgrPieChart
ref={this.chartRef}
valueMemberPath="value"
labelMemberPath="summary"
labelsPosition="OutsideEnd"
legendLabelMemberPath="category"
outlines="white"
radiusFactor="0.7"
labelExtent="30"
dataSource={this.energyGlobalDemand}
legend={this.legend}>
</IgrPieChart>
</div>
</div>
);
}
private _energyGlobalDemand: EnergyGlobalDemand = null;
public get energyGlobalDemand(): EnergyGlobalDemand {
if (this._energyGlobalDemand == null)
{
this._energyGlobalDemand = new EnergyGlobalDemand();
}
return this._energyGlobalDemand;
}
}
// rendering above component in the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);
tsx/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
css
React 円チャートその他の分類項目
円チャート コンポーネントの基本データに、小さい値を含む多くの項目が含まれる場合があります。この場合、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 React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrItemLegendModule, IgrPieChartModule } from "@infragistics/igniteui-react-charts";
import { IgrItemLegend, IgrPieChart } from "@infragistics/igniteui-react-charts";
import { EnergyGlobalDemandItem, EnergyGlobalDemand } from './EnergyGlobalDemand';
const mods: any[] = [
IgrItemLegendModule,
IgrPieChartModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private legend: IgrItemLegend
private legendRef(r: IgrItemLegend) {
this.legend = r;
this.setState({});
}
private chart: IgrPieChart
private chartRef(r: IgrPieChart) {
this.chart = r;
this.setState({});
}
constructor(props: any) {
super(props);
this.legendRef = this.legendRef.bind(this);
this.chartRef = this.chartRef.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="legend-title">
Global Electricity Demand by Energy Use
</div>
<div className="legend">
<IgrItemLegend
ref={this.legendRef}
orientation="Horizontal">
</IgrItemLegend>
</div>
<div className="container fill">
<IgrPieChart
ref={this.chartRef}
labelMemberPath="summary"
labelsPosition="OutsideEnd"
labelExtent="30"
valueMemberPath="value"
outlines="white"
othersCategoryThreshold="10"
othersCategoryType="Number"
othersCategoryText="Others"
radiusFactor="0.7"
legendLabelMemberPath="category"
dataSource={this.energyGlobalDemand}
legend={this.legend}>
</IgrPieChart>
</div>
</div>
);
}
private _energyGlobalDemand: EnergyGlobalDemand = null;
public get energyGlobalDemand(): EnergyGlobalDemand {
if (this._energyGlobalDemand == null)
{
this._energyGlobalDemand = new EnergyGlobalDemand();
}
return this._energyGlobalDemand;
}
}
// rendering above component in the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);
tsx/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
css
React 円チャートの展開
円チャート コンポーネントは個々の円スライスの選択と展開だけでなく、選択状態を変更しカスタム ロジックを実装することを可能にする SliceClick
イベントをコンポーネントサポートします。
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrItemLegend } from "@infragistics/igniteui-react-charts";
import { IgrItemLegendModule } from "@infragistics/igniteui-react-charts";
import { IgrPieChart } from "@infragistics/igniteui-react-charts";
import { IgrPieChartModule } from "@infragistics/igniteui-react-charts";
import { IgrPieChartBase } from "@infragistics/igniteui-react-charts";
import { IIgrPieChartBaseProps } from "@infragistics/igniteui-react-charts";
import { IgrSliceClickEventArgs } from "@infragistics/igniteui-react-charts";
IgrPieChartModule.register();
IgrItemLegendModule.register();
export default class PieChartExplosion extends React.Component<any, any> {
public data: any[];
public chart: IgrPieChart;
public legend: IgrItemLegend;
constructor(props: any) {
super(props);
this.onChartRef = this.onChartRef.bind(this);
this.onLegendRef = this.onLegendRef.bind(this);
this.state = {
data: [
{ MarketShare: 37, Company: "Space Cooling", Summary:"Space Cooling 37%", },
{ MarketShare: 25, Company: "Residential Appliance", Summary:"Residential Appliance 25%", },
{ MarketShare: 12, Company: "Heating", Summary:"Heating 12%", },
{ MarketShare: 8, Company: "Lighting", Summary:"Lighting 8%", },
{ MarketShare: 18, Company: "Other Services", Summary:"Other Services 18%", },
] };
}
public onChartRef(chart: IgrPieChart) {
if (!chart) { return; }
this.chart = chart;
if (this.legend) {
this.chart.legend = this.legend;
}
}
public onLegendRef(legend: IgrItemLegend) {
if (!legend) { return; }
this.legend = legend;
if (this.chart) {
this.chart.legend = this.legend;
}
}
public render(): JSX.Element {
return (
<div className="container sample">
<label className="legend-title">Global Electricity Demand by Energy Use</label>
<div className="options vertical">
<IgrItemLegend ref={this.onLegendRef} orientation="Horizontal" />
</div>
<div className="container">
<IgrPieChart dataSource={this.state.data}
ref={this.onChartRef}
labelMemberPath="Summary"
valueMemberPath="MarketShare"
legendLabelMemberPath="Company"
width="100%"
height="100%"
labelsPosition="OutsideEnd"
labelExtent="30"
explodedRadius={0.2}
explodedSlices="1"
allowSliceExplosion="true"
radiusFactor={0.7}
sliceClick={this.onSliceClick}
startAngle ={-60}/>
</div>
</div>
);
}
public onSliceClick = (s: IgrPieChartBase<IIgrPieChartBaseProps>, e: IgrSliceClickEventArgs) => {
e.isExploded = !e.isExploded;
}
}
// rendering above class to the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<PieChartExplosion/>);
tsx
React 円チャートの選択
デフォルトで、円チャートはマウス クリックによるスライス選択をサポートします。選択されたスライスは、selectedItems
プロパティで取得します。選択したスライスがハイライト表示されます。
円チャートのモードは selectionMode
プロパティで設定します。デフォルト値は Single
です。選択機能を無効化するためにはプロパティを Manual
に設定します。
円チャート コンポーネントは、選択モードを 3 つコンポーネントサポートします。
- Single - single モードに設定すると、一度に 1 つのスライスのみ選択します。他のスライスを選択すると、最初に選択したスライスは選択解除され、新しいスライスが選択されます。
- Multiple - Multiple モードに設定すると、一度に複数のスライスを選択します。スライスをクリックするとスライスが選択され、他のスライスをクリックすると、最初のスライスも、新しくクリックしたスライスも選択されます。
- 手動 - Manual モードに設定すると、選択は無効化されます。
円チャート コンポーネントには、選択機能に関連する 4 つのイベントがあります。
- SelectedItemChanging
- SelectedItemChanged
- SelectedItemsChanging
- SelectedItemsChanged
「Changing」で終わるイベントはキャンセル可能なイベントです。すなわち、イベント引数プロパティ Cancel
を true に設定することで、スライスの選択を停止します。True に設定すると、関連付けられたプロパティは更新されず、その結果スライスは選択されません。この設定はたとえば、スライスのデータによって一定のスライスの選択を無効化する場合に使用します。
「その他」スライスをクリックすると、IgrPieSliceOthersContext
オブジェクトが返されます。オブジェクトは、「その他」スライスに含まれるデータ項目のリストがあります。
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrItemLegend } from "@infragistics/igniteui-react-charts";
import { IgrItemLegendModule } from "@infragistics/igniteui-react-charts";
import { IgrPieChart } from "@infragistics/igniteui-react-charts";
import { IgrPieChartModule } from "@infragistics/igniteui-react-charts";
import { IgrPieChartBase } from "@infragistics/igniteui-react-charts";
import { IIgrPieChartBaseProps } from "@infragistics/igniteui-react-charts";
import { IgrSliceClickEventArgs } from "@infragistics/igniteui-react-charts";
IgrPieChartModule.register();
IgrItemLegendModule.register();
export default class PieChartSelection extends React.Component<any, any> {
public data: any[];
public chart: IgrPieChart;
public legend: IgrItemLegend;
constructor(props: any) {
super(props);
this.state = { data: [
{ MarketShare: 37, Company: "Space Cooling", Summary:"Space Cooling 37%", },
{ MarketShare: 25, Company: "Residential Appliance", Summary:"Residential Appliance 25%", },
{ MarketShare: 12, Company: "Heating", Summary:"Heating 12%", },
{ MarketShare: 8, Company: "Lighting", Summary:"Lighting 8%", },
{ MarketShare: 18, Company: "Other Services", Summary:"Other Services 18%", },
] };
this.onPieRef = this.onPieRef.bind(this);
this.onLegendRef = this.onLegendRef.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample">
<label className="legend-title">Global Electricity Demand by Energy Use</label>
<div className="options vertical">
<IgrItemLegend ref={this.onLegendRef} orientation="Horizontal" />
</div>
<div className="container">
<IgrPieChart dataSource={this.state.data}
ref={this.onPieRef}
labelMemberPath="Summary"
valueMemberPath="MarketShare"
legendLabelMemberPath="Company"
width="100%"
height="calc(100% - 45px)"
selectionMode="multiple"
selectedSliceStroke="white"
selectedSliceFill="rgb(143,143,143)"
selectedSliceOpacity = "1.0"
selectedSliceStrokeThickness= "2"
labelsPosition="OutsideEnd"
labelExtent="30"
radiusFactor={0.7}
selectedItem="1"
startAngle={-60}
/>
</div>
</div>
);
}
public onPieRef(chart: IgrPieChart) {
if (!chart) { return; }
this.chart = chart;
if (this.legend) {
this.chart.legend = this.legend;
}
}
public onLegendRef(legend: IgrItemLegend) {
if (!legend) { return; }
this.legend = legend;
if (this.chart) {
this.chart.legend = this.legend;
}
}
}
// rendering above class to the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<PieChartSelection/>);
tsx
React 円チャートのアニメーション
チャートの半径をスケールする radiusFactor
プロパティを設定して円チャートをすばやくアニメーション化できます。startAngle
プロパティを設定してチャートが回転する間、チャートの角度が増加し続けるようにします。
以下のコードでは、radiusFactor がチャートをサイズの 0.25% 増加し、startAngle がチャートを 1 度回転しています。radiusFactor と startAngle が最大値に達すると、アニメーション フラグをリセットし、間隔をクリアしてアニメーションを停止します。
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrPieChart } from "@infragistics/igniteui-react-charts";
import { IgrPieChartModule } from "@infragistics/igniteui-react-charts";
IgrPieChartModule.register();
export default class PieChartAnimation extends React.Component<any, any> {
public data: any[];
public chart: IgrPieChart;
public isAnimating: boolean = false;
public interval: number = -1;
constructor(props: any) {
super(props);
this.state = {
data: [
{ MarketShare: 37, Category: "Cooling" , Summary: "Cooling 37%" },
{ MarketShare: 25, Category: "Residential" , Summary: "Cooling 25%" },
{ MarketShare: 12, Category: "Heating" , Summary: "Cooling 12%" },
{ MarketShare: 11, Category: "Lighting" , Summary: "Cooling 11%" },
{ MarketShare: 15, Category: "Other" , Summary: "Cooling 15%" }
]
};
this.onPieRef = this.onPieRef.bind(this);
this.onAnimationToggle = this.onAnimationToggle.bind(this);
this.onAnimationClear = this.onAnimationClear.bind(this);
}
public render(): JSX.Element {
return (
<div className="container vertical">
<div className="options horizontal">
<button onClick={this.onAnimationToggle}>Animate Chart</button>
</div>
<div className="container vertical">
<IgrPieChart
width="100%"
height="100%"
ref={this.onPieRef}
dataSource={this.state.data}
labelMemberPath="Summary"
legendLabelMemberPath="Category"
valueMemberPath="MarketShare"
labelsPosition="InsideEnd"
startAngle={0}
labelExtent={0.7}
radiusFactor={0.1} />
</div>
</div>
);
}
public onPieRef(chart: IgrPieChart) {
if (!chart) { return; }
this.chart = chart;
this.onAnimationClear();
this.onAnimationToggle();
}
public componentWillUnmount() {
this.onAnimationClear();
}
public onAnimationToggle = () => {
if (!this.isAnimating) {
this.chart.startAngle = 0;
this.chart.radiusFactor = 0.1;
this.isAnimating = true;
this.interval = window.setInterval(() => this.tick(), 15);
} else {
this.isAnimating = false;
this.onAnimationClear();
}
}
public onAnimationClear(): void {
if (this.interval >= 0) {
window.clearInterval(this.interval);
this.interval = -1;
}
}
public tick(): void {
if (this.isAnimating) {
if (this.chart.radiusFactor < 1.0)
this.chart.radiusFactor += 0.0025;
if (this.chart.startAngle < 360)
this.chart.startAngle++;
if (this.chart.radiusFactor >= 1.0 &&
this.chart.startAngle >= 360) {
this.isAnimating = false;
this.onAnimationClear();
}
}
}
}
// rendering above class to the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<PieChartAnimation/>);
tsx
React 円チャートのスタイル設定
円チャートを作成したら、次に示すように、チャートのスライスの色を変更するなど、スタイルをさらにカスタマイズすることができます。
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 React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrPieChartModule, IgrItemLegendModule } from "@infragistics/igniteui-react-charts";
import { IgrItemLegend, IgrPieChart } from "@infragistics/igniteui-react-charts";
import { EnergyGlobalDemandItem, EnergyGlobalDemand } from './EnergyGlobalDemand';
const mods: any[] = [
IgrPieChartModule,
IgrItemLegendModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private legend: IgrItemLegend
private legendRef(r: IgrItemLegend) {
this.legend = r;
this.setState({});
}
private chart: IgrPieChart
private chartRef(r: IgrPieChart) {
this.chart = r;
this.setState({});
}
constructor(props: any) {
super(props);
this.legendRef = this.legendRef.bind(this);
this.chartRef = this.chartRef.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="legend-title">
Global Electricity Demand by Energy Use
</div>
<div className="legend">
<IgrItemLegend
ref={this.legendRef}
orientation="Horizontal">
</IgrItemLegend>
</div>
<div className="container fill">
<IgrPieChart
ref={this.chartRef}
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={this.energyGlobalDemand}
legend={this.legend}>
</IgrPieChart>
</div>
</div>
);
}
private _energyGlobalDemand: EnergyGlobalDemand = null;
public get energyGlobalDemand(): EnergyGlobalDemand {
if (this._energyGlobalDemand == null)
{
this._energyGlobalDemand = new EnergyGlobalDemand();
}
return this._energyGlobalDemand;
}
}
// rendering above component in the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);
tsx/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
css
React ラジアル円チャート
ラジアル円チャートはラジアル チャートのグループに属し、チャートの中心からデータ ポイントの位置に向かって伸びる円スライスを使用します。このチャート タイプは、複数の一連のデータ ポイントを分類するという概念を採用しており、データ ポイントを水平線に沿って引き伸ばすのではなく、円形の軸に沿ってラップします。
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 React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrLegendModule, IgrDataChartCoreModule, IgrDataChartRadialModule, IgrDataChartRadialCoreModule, IgrDataChartInteractivityModule, IgrDataChartAnnotationModule } from "@infragistics/igniteui-react-charts";
import { IgrLegend, IgrDataChart, IgrCategoryAngleAxis, IgrNumericRadiusAxis, IgrRadialPieSeries, IgrDataToolTipLayer } from "@infragistics/igniteui-react-charts";
import { FootballPlayerStatsItem, FootballPlayerStats } from './FootballPlayerStats';
const mods: any[] = [
IgrLegendModule,
IgrDataChartCoreModule,
IgrDataChartRadialModule,
IgrDataChartRadialCoreModule,
IgrDataChartInteractivityModule,
IgrDataChartAnnotationModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private legend: IgrLegend
private legendRef(r: IgrLegend) {
this.legend = r;
this.setState({});
}
private chart: IgrDataChart
private chartRef(r: IgrDataChart) {
this.chart = r;
this.setState({});
}
private angleAxis: IgrCategoryAngleAxis
private radiusAxis: IgrNumericRadiusAxis
private radialPieSeries1: IgrRadialPieSeries
private radialPieSeries2: IgrRadialPieSeries
private dataToolTipLayer: IgrDataToolTipLayer
constructor(props: any) {
super(props);
this.legendRef = this.legendRef.bind(this);
this.chartRef = this.chartRef.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="legend-title">
Ronaldo vs Messi Player Stats
</div>
<div className="legend">
<IgrLegend
ref={this.legendRef}
orientation="Horizontal">
</IgrLegend>
</div>
<div className="container fill">
<IgrDataChart
ref={this.chartRef}
legend={this.legend}
isHorizontalZoomEnabled="false"
isVerticalZoomEnabled="false">
<IgrCategoryAngleAxis
name="angleAxis"
dataSource={this.footballPlayerStats}
label="attribute">
</IgrCategoryAngleAxis>
<IgrNumericRadiusAxis
name="radiusAxis"
innerRadiusExtentScale="0.1"
interval="2"
minimumValue="0"
maximumValue="10">
</IgrNumericRadiusAxis>
<IgrRadialPieSeries
name="RadialPieSeries1"
dataSource={this.footballPlayerStats}
angleAxisName="angleAxis"
valueAxisName="radiusAxis"
valueMemberPath="ronaldo"
showDefaultTooltip="false"
areaFillOpacity="0.8"
thickness="3"
title="Ronaldo">
</IgrRadialPieSeries>
<IgrRadialPieSeries
name="RadialPieSeries2"
dataSource={this.footballPlayerStats}
angleAxisName="angleAxis"
valueAxisName="radiusAxis"
valueMemberPath="messi"
showDefaultTooltip="false"
areaFillOpacity="0.8"
thickness="3"
title="Messi">
</IgrRadialPieSeries>
<IgrDataToolTipLayer
name="dataToolTipLayer">
</IgrDataToolTipLayer>
</IgrDataChart>
</div>
</div>
);
}
private _footballPlayerStats: FootballPlayerStats = null;
public get footballPlayerStats(): FootballPlayerStats {
if (this._footballPlayerStats == null)
{
this._footballPlayerStats = new FootballPlayerStats();
}
return this._footballPlayerStats;
}
}
// rendering above component in the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);
tsx/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
css
その他のリソース
API リファレンス
以下のテーブルは、上記のセクションで説明した API メンバーをリストします。
legendItemBadgeTemplate
legendItemTemplate
legendLabelMemberPath
othersCategoryThreshold
othersCategoryType
selectionMode
チャート タイプ | コントロール名 | API メンバー |
---|---|---|
円チャート | IgrPieChart |
PieChart |
ラジアル円チャート | IgrDataChart |
IgrRadialPieSeries |