React チャートのオーバーレイ
React IgrDataChart
を使用すると、IgrValueOverlay
を使用して定義した単一の数値で水平線または垂直線を配置できます。特定のシリーズの平均値や中央値などのデータを視覚化するのに役立ちます。
React 値オーバーレイの例
次の例は、いくつかの水平値オーバーレイがプロットされた縦棒チャート を示しています。
import React from 'react' ;
import ReactDOM from 'react-dom/client' ;
import './index.css' ;
import { IgrNumericYAxis } from "@infragistics/igniteui-react-charts" ;
import { IgrCategoryXAxis } from "@infragistics/igniteui-react-charts" ;
import { IgrColumnSeries } from "@infragistics/igniteui-react-charts" ;
import { IgrValueOverlay } from "@infragistics/igniteui-react-charts" ;
import { IgrDataChart } from "@infragistics/igniteui-react-charts" ;
import { IgrDataChartCoreModule } from "@infragistics/igniteui-react-charts" ;
import { IgrDataChartCategoryModule } from "@infragistics/igniteui-react-charts" ;
import { IgrDataChartInteractivityModule } from "@infragistics/igniteui-react-charts" ;
import { IgrLegend } from "@infragistics/igniteui-react-charts" ;
import { IgrLegendModule } from "@infragistics/igniteui-react-charts" ;
IgrDataChartCoreModule.register();
IgrDataChartCategoryModule.register();
IgrDataChartInteractivityModule.register();
IgrLegendModule.register();
export default class DataChartValueOverlay extends React.Component <any, any> {
public data: any [];
public chart: IgrDataChart;
public legend: IgrLegend;
constructor (props: any ) {
super (props);
this .onChartRef = this .onChartRef.bind(this );
this .onLegendRef = this .onLegendRef.bind(this );
this .initData();
}
public render (): JSX .Element {
return (
<div className ="container sample" >
<div className ="container" style ={{height: "calc (100 % - 35px )"}}>
<IgrDataChart width ="100%"
height ="100%"
dataSource ={this.data}
isHorizontalZoomEnabled ={true}
isVerticalZoomEnabled ={true} >
<IgrCategoryXAxis name ="xAxis" label ="Label" />
<IgrNumericYAxis name ="yAxis" minimumValue ={0} maximumValue ={10} />
<IgrColumnSeries name ="series1" xAxisName ="xAxis" yAxisName ="yAxis" valueMemberPath ="Value" />
<IgrValueOverlay name ="overlay1" axisName ="yAxis" value ={2.0} thickness ={5} />
<IgrValueOverlay name ="overlay2" axisName ="yAxis" value ={3.6} thickness ={5} />
<IgrValueOverlay name ="overlay3" axisName ="yAxis" value ={5.8} thickness ={5} />
<IgrValueOverlay name ="overlay4" axisName ="yAxis" value ={1.0} thickness ={5} />
<IgrValueOverlay name ="overlay5" axisName ="yAxis" value ={8.0} thickness ={5} />
<IgrValueOverlay name ="overlay6" axisName ="yAxis" value ={7.0} thickness ={5} />
<IgrValueOverlay name ="overlay7" axisName ="yAxis" value ={5.0} thickness ={5} />
</IgrDataChart >
</div >
</div >
);
}
public initData() {
this .data = [
{ "Label" : 1 , "Value" : 1.0 },
{ "Label" : 2 , "Value" : 2.0 },
{ "Label" : 3 , "Value" : 6.0 },
{ "Label" : 4 , "Value" : 8.0 },
{ "Label" : 5 , "Value" : 2.0 },
{ "Label" : 6 , "Value" : 6.0 },
{ "Label" : 7 , "Value" : 4.0 },
{ "Label" : 8 , "Value" : 2.0 },
{ "Label" : 9 , "Value" : 1.0 },
];
}
public onChartRef(chart: IgrDataChart) {
if (!chart) { return ; }
this .chart = chart;
if (this .legend) {
this .chart.legend = this .legend;
}
}
public onLegendRef(legend: IgrLegend) {
if (!legend) { return ; }
this .legend = legend;
if (this .chart) {
this .chart.legend = this .legend;
}
}
}
const root = ReactDOM.createRoot (document.getElementById('root' ));
root.render (<DataChartValueOverlay /> );
tsx コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Reactツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
React 値オーバーレイのプロパティ
データバインディングに DataSource
を使用する他のシリーズ タイプとは異なり、値オーバーレイは ValueMemberPath
プロパティを使用して単一の数値をバインドします。さらに、値オーバーレイでは、使用する単一の axis
を定義する必要があります。X 軸を使用する場合、値のオーバーレイは垂直線になり、Y 軸を使用する場合は、水平線になります。
数値の X 軸または Y 軸を使用する場合、ValueMemberPath
プロパティは、値のオーバーレイを描画する軸上の実際の数値を反映する必要があります。カテゴリ X または Y 軸を使用する場合、ValueMemberPath
は、値オーバーレイを表示するカテゴリのインデックスを反映する必要があります。
数値オーバーレイを角度角軸で使用すると、チャートの中心からの線として表示され、半径半径軸を使用すると、円として表示されます。
IgrValueOverlay
外観プロパティは、IgrSeries
から継承されているため、例えば brush
と thickness
を使用でき、他のタイプのシリーズと同じように機能します。
IgrValueOverlay
に軸注釈を表示して、所有する軸にオーバーレイの値を表示することもできます。これを示すために、isAxisAnnotationEnabled
プロパティを true に設定できます。
React 値レイヤー
React チャート コンポーネントは、値の線を使用して、最小値、最大値、平均値などのデータのさまざまな焦点を示す機能も公開します。
IgrCategoryChart
および IgrFinancialChart
コンポーネントに IgrValueLayer
を適用するには、チャート上で valueLines
プロパティを設定します。このプロパティは、ValueLayerValueMode
列挙体のコレクションを受け取ります。複数の ValueLayerValueMode
列挙をチャートの valueLines
コレクションに追加することで、同じチャート内で複数の値レイヤーを組み合わせたりできます。
IgrDataChart
では、これは、チャートの IgrSeries
コレクションに IgrValueLayer
を追加し、次に valueMode
プロパティを ValueLayerValueMode
列挙の 1 つに設定することによって行われます。これらの各列挙とその意味を以下に示します。
IgrValueLayer
要素を使用するときに特定のシリーズが考慮されないようにする場合は、レイヤーに targetSeries
プロパティを設定できます。これにより、レイヤーは定義したシリーズを強制的にターゲットにするようになります。単一の IgrDataChart
内に必要な数の IgrValueLayer
要素を含めることができます。
次のサンプルは、IgrCategoryChart
内のさまざまな valueLines
の使用法を示しています。
export class CountryRenewableElectricityItem {
public constructor (init: Partial<CountryRenewableElectricityItem> ) {
Object .assign(this , init);
}
public year: string ;
public europe: number ;
public china: number ;
public america: number ;
}
export class CountryRenewableElectricity extends Array <CountryRenewableElectricityItem > {
public constructor (items: Array <CountryRenewableElectricityItem> | number = -1 ) {
if (Array .isArray(items)) {
super (...items);
} else {
const newItems = [
new CountryRenewableElectricityItem(
{
year : `2009` ,
europe : 34 ,
china : 21 ,
america : 19
}),
new CountryRenewableElectricityItem(
{
year : `2010` ,
europe : 43 ,
china : 26 ,
america : 24
}),
new CountryRenewableElectricityItem(
{
year : `2011` ,
europe : 66 ,
china : 29 ,
america : 28
}),
new CountryRenewableElectricityItem(
{
year : `2012` ,
europe : 69 ,
china : 32 ,
america : 26
}),
new CountryRenewableElectricityItem(
{
year : `2013` ,
europe : 58 ,
china : 47 ,
america : 38
}),
new CountryRenewableElectricityItem(
{
year : `2014` ,
europe : 40 ,
china : 46 ,
america : 31
}),
new CountryRenewableElectricityItem(
{
year : `2015` ,
europe : 78 ,
china : 50 ,
america : 19
}),
new CountryRenewableElectricityItem(
{
year : `2016` ,
europe : 13 ,
china : 90 ,
america : 52
}),
new CountryRenewableElectricityItem(
{
year : `2017` ,
europe : 78 ,
china : 132 ,
america : 50
}),
new CountryRenewableElectricityItem(
{
year : `2018` ,
europe : 40 ,
china : 134 ,
america : 34
}),
new CountryRenewableElectricityItem(
{
year : `2018` ,
europe : 40 ,
china : 134 ,
america : 34
}),
new CountryRenewableElectricityItem(
{
year : `2019` ,
europe : 80 ,
china : 96 ,
america : 38
}),
];
super (...newItems.slice(0 ));
}
}
}
ts コピー import 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 { CountryRenewableElectricityItem, CountryRenewableElectricity } from './CountryRenewableElectricity' ;
import { IgrPropertyEditorPropertyDescriptionChangedEventArgs } from "@infragistics/igniteui-react-layouts" ;
import { MarkerType, MarkerType_$type } from "@infragistics/igniteui-react-charts" ;
import { EnumUtil } from "@infragistics/igniteui-react-core" ;
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 valueListEditor: 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 .editorChangeUpdateValueLines = this .editorChangeUpdateValueLines.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 ="ValueListHandler"
name ="ValueListEditor"
label ="Value List"
shouldOverrideDefaultEditor ="true"
valueType ="EnumValue"
dropDownValues ={[ "Auto ", "Average ", "GlobalAverage ", "GlobalMaximum ", "GlobalMinimum ", "Maximum ", "Minimum "]}
dropDownNames ={[ "Auto ", "Average ", "GlobalAverage ", "GlobalMaximum ", "GlobalMinimum ", "Maximum ", "Minimum "]}
primitiveValue ="Auto"
changed ={this.editorChangeUpdateValueLines} >
</IgrPropertyEditorPropertyDescription >
</IgrPropertyEditorPanel >
</div >
<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}
dataSource ={this.countryRenewableElectricity}
includedProperties ={[ "year ", "america ", "europe "]}
chartType ="Column"
legend ={this.legend}
isHorizontalZoomEnabled ="false"
isVerticalZoomEnabled ="false"
crosshairsDisplayMode ="None"
isTransitionInEnabled ="false"
yAxisMinimumValue ="0"
yAxisMaximumValue ="100" >
</IgrCategoryChart >
</div >
</div >
);
}
private _countryRenewableElectricity: CountryRenewableElectricity = null ;
public get countryRenewableElectricity(): CountryRenewableElectricity {
if (this ._countryRenewableElectricity == null )
{
this ._countryRenewableElectricity = new CountryRenewableElectricity();
}
return this ._countryRenewableElectricity;
}
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;
}
public editorChangeUpdateValueLines(sender: any , args: IgrPropertyEditorPropertyDescriptionChangedEventArgs): void {
var item = sender as IgrPropertyEditorPropertyDescription;
var chart = this .chart;
var valueLineType = item.primitiveValue;
chart.valueLines = valueLineType;
}
}
const root = ReactDOM.createRoot (document.getElementById('root' ));
root.render (<Sample /> );
tsx コピー
React ファイナンシャル オーバーレイ
React 株価チャート に組み込みのファイナンシャル オーバーレイとインジケーターをプロットすることもできます。
その他のリソース
関連するチャート タイプの詳細については、以下のトピックを参照してください。
API リファレンス
以下は、上記のセクションで説明した API メンバーのリストです。