React チャートの選択
React {ComponentTitle} の Ignite UI for React 選択機能を使用すると、ユーザーはチャート内の単一または複数のシリーズを対話的に選択、ハイライト表示、アウトライン表示したり、その逆の選択を解除したりできます。これにより、提示されたデータをユーザーがより意味のある方法で操作するさまざまな可能性が提供されます。
選択の設定
デフォルトの動作 selectionMode
はオフになっており、次のいずれかのオプションを選択する必要があります。{ComponentName}
に使用可能な選択モードがいくつかあります。
- Auto
- None
- Brighten
- FadeOthers
- GrayscaleOthers
- FocusColorThickOutline
- FocusColorOutline
- SelectionColorThickOutline
- SelectionColorOutline
- FocusColorFill
- SelectionColorFill
- ThickOutline
Brighten
は選択した項目をフェードアウトしますが、FadeOthers
は反対の効果を引き起こします。
GrayscaleOthers
は FadeOthers
と同様に動作しますが、シリーズの残りの部分にはグレー色を表示します。これは selectionBrush
設定をオーバーライドすることに注意してください。
SelectionColorOutline
と SelectionColorThickOutline
はシリーズの周囲に境界線を描画します。
併せて、どの項目を選択するかをより細かく制御できる selectionBehavior
も利用できます。Auto のデフォルトの動作は PerSeriesAndDataItemMultiSelect
です。
- Auto
- PerDataItemMultiSelect
- PerDataItemSingleSelect
- PerSeriesAndDataItemMultiSelect
- PerSeriesAndDataItemSingleSelect
- PerSeriesAndDataItemGlobalSingleSelect
- PerSeriesMultiSelect
- PerSeriesSingleSelect
Color Fill (塗りつぶし) による選択の設定
次の例は、SelectionColorFill
と Auto
の両方の選択動作の組み合わせ、つまり PerSeriesAndDataItemMultiSelect
を示しています。塗りつぶしは、シリーズ項目全体の背景色を変更するため、便利な視覚的な合図を提供します。各項目をクリックすると、項目が緑から紫に変わります。
export class TemperatureAverageDataItem {
public constructor(init: Partial<TemperatureAverageDataItem>) {
Object.assign(this, init);
}
public month: string;
public temperature: number;
}
export class TemperatureAverageData extends Array<TemperatureAverageDataItem> {
public constructor(items: Array<TemperatureAverageDataItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new TemperatureAverageDataItem(
{
month: `Jan`,
temperature: 3
}),
new TemperatureAverageDataItem(
{
month: `Feb`,
temperature: 4
}),
new TemperatureAverageDataItem(
{
month: `Mar`,
temperature: 9
}),
new TemperatureAverageDataItem(
{
month: `Apr`,
temperature: 15
}),
new TemperatureAverageDataItem(
{
month: `May`,
temperature: 21
}),
new TemperatureAverageDataItem(
{
month: `Jun`,
temperature: 26
}),
new TemperatureAverageDataItem(
{
month: `Jul`,
temperature: 29
}),
new TemperatureAverageDataItem(
{
month: `Aug`,
temperature: 28
}),
new TemperatureAverageDataItem(
{
month: `Sep`,
temperature: 24
}),
new TemperatureAverageDataItem(
{
month: `Oct`,
temperature: 18
}),
new TemperatureAverageDataItem(
{
month: `Nov`,
temperature: 11
}),
new TemperatureAverageDataItem(
{
month: `Dec`,
temperature: 5
}),
];
super(...newItems.slice(0));
}
}
}
tsimport React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrCategoryChartModule, IgrDataChartInteractivityModule } from "@infragistics/igniteui-react-charts";
import { IgrCategoryChart } from "@infragistics/igniteui-react-charts";
import { TemperatureAverageDataItem, TemperatureAverageData } from './TemperatureAverageData';
const mods: any[] = [
IgrCategoryChartModule,
IgrDataChartInteractivityModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private chart: IgrCategoryChart
private chartRef(r: IgrCategoryChart) {
this.chart = r;
this.setState({});
}
constructor(props: any) {
super(props);
this.chartRef = this.chartRef.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="legend-title">
Average Temperature Range in New York
</div>
<div className="container fill">
<IgrCategoryChart
ref={this.chartRef}
chartType="Column"
dataSource={this.temperatureAverageData}
yAxisTitle="Temperature in Degrees Celsius"
yAxisTitleLeftMargin="10"
yAxisTitleRightMargin="5"
yAxisLabelLeftMargin="0"
isHorizontalZoomEnabled="false"
isVerticalZoomEnabled="false"
crosshairsDisplayMode="None"
toolTipType="None"
selectionMode="SelectionColorFill"
selectionBehavior="Auto"
selectionBrush="purple"
focusBrush="purple">
</IgrCategoryChart>
</div>
</div>
);
}
private _temperatureAverageData: TemperatureAverageData = null;
public get temperatureAverageData(): TemperatureAverageData {
if (this._temperatureAverageData == null)
{
this._temperatureAverageData = new TemperatureAverageData();
}
return this._temperatureAverageData;
}
}
// 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ツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
複数選択の構成
その他の選択モードでは、さまざまな選択方法が提供されます。たとえば、PerDataItemMultiSelect
とともに selectionBehavior
を使用すると、複数のシリーズが存在する場合にカテゴリ全体のすべてのシリーズに影響し、カテゴリ間での選択が可能になります。PerDataItemSingleSelect
と比較すると、一度に選択できるのは 1 つのカテゴリの項目のみです。これは、複数のシリーズが異なるデータ ソースにバインドされている場合に役立ち、カテゴリ間の選択をより細かく制御できます。
PerSeriesAndDataItemGlobalSingleSelect
を使用すると、一度にすべてのカテゴリで単一のシリーズを選択できます。
export class EnergyRenewableConsumptionItem {
public constructor(init: Partial<EnergyRenewableConsumptionItem>) {
Object.assign(this, init);
}
public location: string;
public year: number;
public hydro: number;
public solar: number;
public wind: number;
public other: number;
}
export class EnergyRenewableConsumption extends Array<EnergyRenewableConsumptionItem> {
public constructor(items: Array<EnergyRenewableConsumptionItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new EnergyRenewableConsumptionItem(
{
location: `China`,
year: 2019,
hydro: 1269.5,
solar: 223,
wind: 405.2,
other: 102.8
}),
new EnergyRenewableConsumptionItem(
{
location: `Europe`,
year: 2019,
hydro: 632.54,
solar: 154,
wind: 461.3,
other: 220.3
}),
new EnergyRenewableConsumptionItem(
{
location: `USA`,
year: 2019,
hydro: 271.16,
solar: 108,
wind: 303.4,
other: 78.34
}),
new EnergyRenewableConsumptionItem(
{
location: `Brazil`,
year: 2019,
hydro: 399.3,
solar: 5.5,
wind: 55.83,
other: 56.25
}),
new EnergyRenewableConsumptionItem(
{
location: `Canada`,
year: 2019,
hydro: 381.98,
solar: 4.3,
wind: 34.17,
other: 10.81
}),
];
super(...newItems.slice(0));
}
}
}
tsimport React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrPropertyEditorPanelModule } from "@infragistics/igniteui-react-layouts";
import { IgrLegendModule, IgrCategoryChartModule } from "@infragistics/igniteui-react-charts";
import { IgrLegend, IgrCategoryChart } from "@infragistics/igniteui-react-charts";
import { IgrPropertyEditorPanel, IgrPropertyEditorPropertyDescription } from "@infragistics/igniteui-react-layouts";
import { ComponentRenderer, PropertyEditorPanelDescriptionModule, LegendDescriptionModule, CategoryChartDescriptionModule } from "@infragistics/igniteui-react-core";
import { EnergyRenewableConsumptionItem, EnergyRenewableConsumption } from './EnergyRenewableConsumption';
import 'igniteui-webcomponents/themes/light/bootstrap.css';
const mods: any[] = [
IgrPropertyEditorPanelModule,
IgrLegendModule,
IgrCategoryChartModule
];
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 propertyEditor: IgrPropertyEditorPanel
private propertyEditorRef(r: IgrPropertyEditorPanel) {
this.propertyEditor = r;
this.setState({});
}
private selectionModeEditor: IgrPropertyEditorPropertyDescription
private selectionBehaviorEditor: IgrPropertyEditorPropertyDescription
private chart: IgrCategoryChart
private chartRef(r: IgrCategoryChart) {
this.chart = r;
this.setState({});
}
constructor(props: any) {
super(props);
this.legendRef = this.legendRef.bind(this);
this.propertyEditorRef = this.propertyEditorRef.bind(this);
this.chartRef = this.chartRef.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="options vertical">
<IgrPropertyEditorPanel
ref={this.propertyEditorRef}
componentRenderer={this.renderer}
target={this.chart}
descriptionType="CategoryChart"
isHorizontal="true"
isWrappingEnabled="true">
<IgrPropertyEditorPropertyDescription
propertyPath="SelectionMode"
name="SelectionModeEditor"
label="Selection Mode: "
primitiveValue="SelectionColorFill">
</IgrPropertyEditorPropertyDescription>
<IgrPropertyEditorPropertyDescription
propertyPath="SelectionBehavior"
name="SelectionBehaviorEditor"
label="Selection Behavior: "
primitiveValue="PerSeriesAndDataItemGlobalSingleSelect">
</IgrPropertyEditorPropertyDescription>
</IgrPropertyEditorPanel>
</div>
<div className="legend-title">
Highest Grossing Movie Franchises
</div>
<div className="legend">
<IgrLegend
ref={this.legendRef}
orientation="Horizontal">
</IgrLegend>
</div>
<div className="container fill">
<IgrCategoryChart
ref={this.chartRef}
chartType="Column"
dataSource={this.energyRenewableConsumption}
legend={this.legend}
yAxisTitleLeftMargin="10"
yAxisTitleRightMargin="5"
yAxisLabelLeftMargin="0"
isHorizontalZoomEnabled="false"
isVerticalZoomEnabled="false"
crosshairsDisplayMode="None"
selectionMode="SelectionColorFill"
selectionBehavior="PerSeriesAndDataItemGlobalSingleSelect"
selectionBrush="orange"
focusBrush="orange">
</IgrCategoryChart>
</div>
</div>
);
}
private _energyRenewableConsumption: EnergyRenewableConsumption = null;
public get energyRenewableConsumption(): EnergyRenewableConsumption {
if (this._energyRenewableConsumption == null)
{
this._energyRenewableConsumption = new EnergyRenewableConsumption();
}
return this._energyRenewableConsumption;
}
private _componentRenderer: ComponentRenderer = null;
public get renderer(): ComponentRenderer {
if (this._componentRenderer == null) {
this._componentRenderer = new ComponentRenderer();
var context = this._componentRenderer.context;
PropertyEditorPanelDescriptionModule.register(context);
LegendDescriptionModule.register(context);
CategoryChartDescriptionModule.register(context);
}
return this._componentRenderer;
}
}
// 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
アウトライン選択の構成
focusBrush
を適用すると、selectionMode
プロパティがフォーカス オプションの 1 つに設定されている場合に、選択されたシリーズが境界線付きで表示されます。
ラジアル シリーズの選択
この例では、各ラジアル シリーズを異なる色で選択できる IgrDataChart
を介した別のシリーズ タイプを示します。
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 { IgrDataChartCoreModule, IgrDataChartRadialModule, IgrDataChartRadialCoreModule, IgrDataChartInteractivityModule, IgrDataChartAnnotationModule, IgrLegendModule } from "@infragistics/igniteui-react-charts";
import { IgrLegend, IgrDataChart, IgrCategoryAngleAxis, IgrNumericRadiusAxis, IgrRadialColumnSeries } from "@infragistics/igniteui-react-charts";
import { FootballPlayerStatsItem, FootballPlayerStats } from './FootballPlayerStats';
const mods: any[] = [
IgrDataChartCoreModule,
IgrDataChartRadialModule,
IgrDataChartRadialCoreModule,
IgrDataChartInteractivityModule,
IgrDataChartAnnotationModule,
IgrLegendModule
];
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 radialColumnSeries1: IgrRadialColumnSeries
private radialColumnSeries2: IgrRadialColumnSeries
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"
selectionMode="SelectionColorFill"
selectionBehavior="PerSeriesMultiSelect">
<IgrCategoryAngleAxis
name="angleAxis"
dataSource={this.footballPlayerStats}
label="attribute">
</IgrCategoryAngleAxis>
<IgrNumericRadiusAxis
name="radiusAxis"
innerRadiusExtentScale="0.1"
interval="2"
minimumValue="0"
maximumValue="10">
</IgrNumericRadiusAxis>
<IgrRadialColumnSeries
name="RadialColumnSeries1"
dataSource={this.footballPlayerStats}
angleAxisName="angleAxis"
valueAxisName="radiusAxis"
valueMemberPath="ronaldo"
showDefaultTooltip="false"
areaFillOpacity="0.8"
thickness="3"
title="Ronaldo"
selectionBrush="yellow">
</IgrRadialColumnSeries>
<IgrRadialColumnSeries
name="RadialColumnSeries2"
dataSource={this.footballPlayerStats}
angleAxisName="angleAxis"
valueAxisName="radiusAxis"
valueMemberPath="messi"
showDefaultTooltip="false"
areaFillOpacity="0.8"
thickness="3"
title="Messi"
selectionBrush="cyan">
</IgrRadialColumnSeries>
</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
プログラムによる選択
チャートの選択項目は、起動時や実行時にチャートの選択項目を表示するようにコードで設定することもできます。これは、IgrCategoryChart
の SelectedSeriesCollection
に項目を追加することで実現できます。IgrChartSelection
オブジェクトの matcher
プロパティを使用すると、「マッチャー」に基づいてシリーズを選択できます。これはチャートから実際のシリーズにアクセスできない場合に最適です。データ ソースに含まれるプロパティがわかっていれば、シリーズが使用される ValueMemberPath
を使用できます。
マッチャーは、IgrDataChart
のように実際のシリーズにアクセスできない場合、IgrCategoryChart
などのチャートで使用するのに最適です。この場合、データ ソースに含まれるプロパティがわかっていれば、シリーズに含まれる ValueMemberPaths を推測できます。たとえば、データ ソースに Nuclear、Coal、Oil、Solar という数値プロパティがある場合、これらのプロパティごとにシリーズが作成されていることがわかります。Solar 値にバインドされたシリーズをハイライト表示する場合は、次のプロパティが設定されたマッチャーを使用して、ChartSelection オブジェクトを selectedSeriesItems
コレクションに追加できます。
たとえば、データ ソースに Nuclear、Coal、Oil、Solar という数値プロパティがある場合、これらのプロパティごとにシリーズが作成されていることがわかります。Solar 値にバインドされたシリーズを選択する場合は、次のプロパティが設定されたマッチャーを使用して、ChartSelection オブジェクトを SelectedSeriesItems コレクションに追加できます。
export class EnergyRenewableConsumptionItem {
public constructor(init: Partial<EnergyRenewableConsumptionItem>) {
Object.assign(this, init);
}
public location: string;
public year: number;
public hydro: number;
public solar: number;
public wind: number;
public other: number;
}
export class EnergyRenewableConsumption extends Array<EnergyRenewableConsumptionItem> {
public constructor(items: Array<EnergyRenewableConsumptionItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new EnergyRenewableConsumptionItem(
{
location: `China`,
year: 2019,
hydro: 1269.5,
solar: 223,
wind: 405.2,
other: 102.8
}),
new EnergyRenewableConsumptionItem(
{
location: `Europe`,
year: 2019,
hydro: 632.54,
solar: 154,
wind: 461.3,
other: 220.3
}),
new EnergyRenewableConsumptionItem(
{
location: `USA`,
year: 2019,
hydro: 271.16,
solar: 108,
wind: 303.4,
other: 78.34
}),
new EnergyRenewableConsumptionItem(
{
location: `Brazil`,
year: 2019,
hydro: 399.3,
solar: 5.5,
wind: 55.83,
other: 56.25
}),
new EnergyRenewableConsumptionItem(
{
location: `Canada`,
year: 2019,
hydro: 381.98,
solar: 4.3,
wind: 34.17,
other: 10.81
}),
];
super(...newItems.slice(0));
}
}
}
tsimport React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrLegendModule, IgrCategoryChartModule, IgrDataChartAnnotationModule, IgrDataChartInteractivityModule, IgrDataChartCoreModule } from "@infragistics/igniteui-react-charts";
import { IgrLegend, IgrCategoryChart } from "@infragistics/igniteui-react-charts";
import { ComponentRenderer, LegendDescriptionModule, CategoryChartDescriptionModule, DataChartAnnotationDescriptionModule, DataChartInteractivityDescriptionModule, DataChartCoreDescriptionModule } from "@infragistics/igniteui-react-core";
import { EnergyRenewableConsumptionItem, EnergyRenewableConsumption } from './EnergyRenewableConsumption';
import { IgrChartSelection, IgrSeriesMatcher } from "@infragistics/igniteui-react-charts";
const mods: any[] = [
IgrLegendModule,
IgrCategoryChartModule,
IgrDataChartAnnotationModule,
IgrDataChartInteractivityModule,
IgrDataChartCoreModule
];
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: IgrCategoryChart
private chartRef(r: IgrCategoryChart) {
this.chart = r;
this.setState({});
}
constructor(props: any) {
super(props);
this.legendRef = this.legendRef.bind(this);
this.chartRef = this.chartRef.bind(this);
}
public componentDidMount() {
this.selectionMatcherOnViewInit();
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="legend-title">
Renewable Electricity Generated
</div>
<div className="legend">
<IgrLegend
ref={this.legendRef}
orientation="Horizontal">
</IgrLegend>
</div>
<div className="container fill">
<IgrCategoryChart
ref={this.chartRef}
legend={this.legend}
dataSource={this.energyRenewableConsumption}
chartType="Column"
crosshairsDisplayMode="None"
yAxisTitle="TWh"
isHorizontalZoomEnabled="false"
isVerticalZoomEnabled="false"
selectionMode="SelectionColorFill"
selectionBehavior="Auto"
selectionBrush="orange">
</IgrCategoryChart>
</div>
</div>
);
}
private _energyRenewableConsumption: EnergyRenewableConsumption = null;
public get energyRenewableConsumption(): EnergyRenewableConsumption {
if (this._energyRenewableConsumption == null)
{
this._energyRenewableConsumption = new EnergyRenewableConsumption();
}
return this._energyRenewableConsumption;
}
private _componentRenderer: ComponentRenderer = null;
public get renderer(): ComponentRenderer {
if (this._componentRenderer == null) {
this._componentRenderer = new ComponentRenderer();
var context = this._componentRenderer.context;
LegendDescriptionModule.register(context);
CategoryChartDescriptionModule.register(context);
DataChartAnnotationDescriptionModule.register(context);
DataChartInteractivityDescriptionModule.register(context);
DataChartCoreDescriptionModule.register(context);
}
return this._componentRenderer;
}
private _timer: ReturnType<typeof setInterval>;
public selectionMatcherOnViewInit(): void {
var chart = this.chart;
this._timer = setInterval(() => {
var data = this.energyRenewableConsumption;
var matcher = new IgrSeriesMatcher();
var selection = new IgrChartSelection();
selection.item = data[1];
matcher.memberPath = "hydro";
matcher.memberPathType = "ValueMemberPath";
selection.matcher = matcher;
chart.selectedSeriesItems.add(selection);
var matcher2 = new IgrSeriesMatcher();
var selection2 = new IgrChartSelection();
selection2.item = data[2];
matcher2.memberPath = "wind";
matcher2.memberPathType = "ValueMemberPath";
selection2.matcher = matcher2;
chart.selectedSeriesItems.add(selection2);
}, 100);
}
}
// 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 メンバーのリストです。
IgrCategoryChart プロパティ |
IgrDataChart プロパティ |
---|---|