React ツールバー コンポーネントは、主にチャート コンポーネントで使用される UI 操作のコンパニオン コンテナーです。ツールバーは、IgrDataChart
または IgrCategoryChart
コンポーネントにリンクされると、プロパティとツール項目のプリセットで動的に更新されます。プロジェクト用のカスタム ツールを作成して、エンド ユーザーが変更を提供できるようになり、無限のカスタマイズが可能になります。
React ツールバーの例
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 { IgrLegendModule, IgrCategoryChartModule, IgrCategoryChartToolbarModule } from "@infragistics/igniteui-react-charts";
import { IgrToolbarModule } from "@infragistics/igniteui-react-layouts";
import { IgrCheckboxListModule } from "@infragistics/igniteui-react-grids";
import { IgrLegend, IgrCategoryChart } from "@infragistics/igniteui-react-charts";
import { IgrToolbar } from "@infragistics/igniteui-react-layouts";
import { CountryRenewableElectricityItem, CountryRenewableElectricity } from './CountryRenewableElectricity';
const mods: any[] = [
IgrLegendModule,
IgrToolbarModule,
IgrCategoryChartModule,
IgrCategoryChartToolbarModule,
IgrCheckboxListModule
];
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 toolbar: IgrToolbar
private toolbarRef(r: IgrToolbar) {
this.toolbar = 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.toolbarRef = this.toolbarRef.bind(this);
this.chartRef = this.chartRef.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="legend-title">
Renewable Electricity Generated
</div>
<div className="aboveContentSplit">
<div className="aboveContentLeftContainer">
<div>
<IgrToolbar
ref={this.toolbarRef}
target={this.chart}
orientation="Horizontal">
</IgrToolbar>
</div>
</div>
<div className="aboveContentRightContainer">
<div>
<IgrLegend
ref={this.legendRef}
orientation="Horizontal">
</IgrLegend>
</div>
</div>
</div>
<div className="container fill">
<IgrCategoryChart
ref={this.chartRef}
chartType="Line"
isHorizontalZoomEnabled="true"
isVerticalZoomEnabled="true"
dataSource={this.countryRenewableElectricity}
includedProperties={["year", "europe", "china", "america"]}
legend={this.legend}
yAxisTitle="TWh"
yAxisTitleLeftMargin="10"
yAxisTitleRightMargin="5"
yAxisLabelLeftMargin="0"
yAxisLabelLocation="OutsideRight"
isTransitionInEnabled="true">
</IgrCategoryChart>
</div>
</div>
);
}
private _countryRenewableElectricity: CountryRenewableElectricity = null;
public get countryRenewableElectricity(): CountryRenewableElectricity {
if (this._countryRenewableElectricity == null)
{
this._countryRenewableElectricity = new CountryRenewableElectricity();
}
return this._countryRenewableElectricity;
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);
tsx
.aboveContentSplit {
display: flex;
flex-direction: row;
}
.aboveContentLeftContainer {
margin-left: 1.25rem;
display: flex;
flex-grow: 1;
justify-content: flex-start;
align-items: flex-end;
}
.aboveContentRightContainer {
margin-right: 1.25rem;
display: flex;
flex-grow: 1;
justify-content: flex-end;
align-items: flex-end;
}
css
このサンプルが気に入りましたか? 完全な Ignite UI for Reactツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
依存関係
Ignite UI for React のレイアウト、入力、チャート、コア パッケージをインストールします。
npm install igniteui-react-layouts
npm install igniteui-react-inputs
npm install igniteui-react-charts
npm install igniteui-react-core
cmd
IgrDataChart
コンポーネントとその機能とともに IgrToolbar
を使用する場合、次のモジュールが必要です。
import { IgxToolbarModule } from 'igniteui-react-layouts';
import { IgrDataChartToolbarModule, IgrDataChartCoreModule, IgrDataChartCategoryModule, IgrDataChartAnnotationModule, IgrDataChartInteractivityModule, IgrDataChartCategoryTrendLineModule } from 'igniteui-react-charts';
IgxToolbarModule.register();
IgrDataChartToolbarModule.register();
IgrDataChartCoreModule.register();
IgrDataChartCategoryModule.register();
IgrDataChartAnnotationModule.register();
IgrDataChartInteractivityModule.register();
IgrDataChartCategoryTrendLineModule.register();
ts
使用方法
ツール操作
以下は、ツールバーに追加できるさまざまな IgrToolAction
項目のリストです。
これらのツールはそれぞれ、マウスのクリックによってトリガーされる OnCommand
イベントを公開します。注: IgrToolActionIconMenu
は、IgrToolActionIconMenu
内にラップすることもできる他のツールのラッパーです。
IgrToolAction
オブジェクトの overlayId
、beforeId
、および afterId
プロパティを使用して、新規および既存のツールの位置を変更したり、非表示にマークしたりすることができます。ToolActions は visibility
プロパティも公開します。
次の例は、いくつかの機能を示しています。まず、ZoomReset や AnalyzeMenu メニュー ツール操作などの組み込みツールを非表示にするなど、IgrToolActionSubPanel
でツールをグループ化できます。この例では、afterId
プロパティを使用して ZoomOut に割り当てることで、ZoomReset ツール操作の新しいインスタンスが追加され、ZoomMenu 内に配置されます。また、ツールの isHighlighted
プロパティによってもハイライト表示されます。これにより、新しいリセット ツールが ZoomMenu の下部にすぐに表示されます。
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 { IgrToolbarModule } from "@infragistics/igniteui-react-layouts";
import { IgrDataChartToolbarModule, IgrDataChartCoreModule, IgrDataChartCategoryModule, IgrDataChartAnnotationModule, IgrDataChartInteractivityModule, IgrDataChartCategoryTrendLineModule } from "@infragistics/igniteui-react-charts";
import { IgrToolbar, IgrToolActionIconMenu, IgrToolActionGroupHeader, IgrToolActionSubPanel, IgrToolActionCheckbox, IgrToolActionLabel } from "@infragistics/igniteui-react-layouts";
import { IgrDataChart, IgrCategoryXAxis, IgrNumericYAxis, IgrLineSeries } from "@infragistics/igniteui-react-charts";
import { CountryRenewableElectricityItem, CountryRenewableElectricity } from './CountryRenewableElectricity';
import { IgrToolCommandEventArgs } from "@infragistics/igniteui-react-layouts";
import { IgrSeries, IgrDataToolTipLayer, IgrCrosshairLayer, IgrFinalValueLayer } from "@infragistics/igniteui-react-charts";
const mods: any[] = [
IgrToolbarModule,
IgrDataChartToolbarModule,
IgrDataChartCoreModule,
IgrDataChartCategoryModule,
IgrDataChartAnnotationModule,
IgrDataChartInteractivityModule,
IgrDataChartCategoryTrendLineModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private toolbar: IgrToolbar
private toolbarRef(r: IgrToolbar) {
this.toolbar = r;
this.setState({});
}
private menuForSubPanelTool: IgrToolActionIconMenu
private subPanelGroup: IgrToolActionGroupHeader
private customSubPanelTools: IgrToolActionSubPanel
private enableTooltipsLabel: IgrToolActionCheckbox
private enableCrosshairsLabel: IgrToolActionCheckbox
private enableFinalValuesLabel: IgrToolActionCheckbox
private zoomResetLabel: IgrToolActionLabel
private zoomResetHidden: IgrToolActionLabel
private analyzeMenu: IgrToolActionIconMenu
private copyMenu: IgrToolActionLabel
private chart: IgrDataChart
private chartRef(r: IgrDataChart) {
this.chart = r;
this.setState({});
}
private xAxis: IgrCategoryXAxis
private yAxis: IgrNumericYAxis
private lineSeries1: IgrLineSeries
private lineSeries2: IgrLineSeries
private lineSeries3: IgrLineSeries
constructor(props: any) {
super(props);
this.toolbarRef = this.toolbarRef.bind(this);
this.toolbarToggleAnnotations = this.toolbarToggleAnnotations.bind(this);
this.chartRef = this.chartRef.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="aboveContentSplit">
<div className="aboveContentLeftContainer">
<div>
<IgrToolbar
ref={this.toolbarRef}
target={this.chart}
orientation="Horizontal"
onCommand={this.toolbarToggleAnnotations}>
<IgrToolActionIconMenu
name="MenuForSubPanelTool"
iconCollectionName="ChartToolbarIcons"
iconName="analyze">
<IgrToolActionGroupHeader
name="SubPanelGroup"
closeOnExecute="true"
title="Visualizations"
subtitle="Layers">
</IgrToolActionGroupHeader>
<IgrToolActionSubPanel
name="CustomSubPanelTools">
<IgrToolActionCheckbox
name="EnableTooltipsLabel"
title="Enable Tooltips"
commandId="EnableTooltips">
</IgrToolActionCheckbox>
<IgrToolActionCheckbox
name="EnableCrosshairsLabel"
title="Enable Crosshairs"
commandId="EnableCrosshairs">
</IgrToolActionCheckbox>
<IgrToolActionCheckbox
name="EnableFinalValuesLabel"
title="Enable Final Values"
commandId="EnableFinalValues">
</IgrToolActionCheckbox>
</IgrToolActionSubPanel>
</IgrToolActionIconMenu>
<IgrToolActionLabel
name="zoomResetLabel"
title="Reset"
afterId="ZoomOut"
iconName="reset"
iconCollectionName="ChartToolbarIcons"
commandId="ZoomReset"
isHighlighted="true">
</IgrToolActionLabel>
<IgrToolActionLabel
name="zoomResetHidden"
overlayId="ZoomReset"
visibility="Collapsed">
</IgrToolActionLabel>
<IgrToolActionIconMenu
name="AnalyzeMenu"
overlayId="AnalyzeMenu"
visibility="Collapsed">
</IgrToolActionIconMenu>
<IgrToolActionLabel
name="CopyMenu"
overlayId="CopyMenu"
visibility="Collapsed">
</IgrToolActionLabel>
</IgrToolbar>
</div>
</div>
</div>
<div className="container fill">
<IgrDataChart
computedPlotAreaMarginMode="Series"
isHorizontalZoomEnabled="true"
isVerticalZoomEnabled="true"
ref={this.chartRef}>
<IgrCategoryXAxis
name="xAxis"
dataSource={this.countryRenewableElectricity}
label="year">
</IgrCategoryXAxis>
<IgrNumericYAxis
name="yAxis"
title="TWh"
labelLocation="OutsideRight">
</IgrNumericYAxis>
<IgrLineSeries
name="lineSeries1"
title="Electricity"
xAxisName="xAxis"
yAxisName="yAxis"
dataSource={this.countryRenewableElectricity}
valueMemberPath="america">
</IgrLineSeries>
<IgrLineSeries
name="LineSeries2"
title="Electricity"
xAxisName="xAxis"
yAxisName="yAxis"
dataSource={this.countryRenewableElectricity}
valueMemberPath="europe">
</IgrLineSeries>
<IgrLineSeries
name="LineSeries3"
title="Electricity"
xAxisName="xAxis"
yAxisName="yAxis"
dataSource={this.countryRenewableElectricity}
valueMemberPath="china">
</IgrLineSeries>
</IgrDataChart>
</div>
</div>
);
}
private _countryRenewableElectricity: CountryRenewableElectricity = null;
public get countryRenewableElectricity(): CountryRenewableElectricity {
if (this._countryRenewableElectricity == null)
{
this._countryRenewableElectricity = new CountryRenewableElectricity();
}
return this._countryRenewableElectricity;
}
public toolbarToggleAnnotations(sender: any, args: IgrToolCommandEventArgs): void {
var target = this.chart;
switch (args.command.commandId)
{
case "EnableTooltips":
var enable = args.command.argumentsList[0].value as boolean;
if (enable)
{
target.series.add(new IgrDataToolTipLayer({ name: "tooltipLayer" }));
}
else
{
var toRemove = null;
for (var i = 0; i < target.actualSeries.length; i++) {
let s = target.actualSeries[i] as IgrSeries;
if (s instanceof IgrDataToolTipLayer)
{
toRemove = s;
}
}
if (toRemove != null)
{
target.series.remove(toRemove);
}
}
break;
case "EnableCrosshairs":
var enable = args.command.argumentsList[0].value as boolean;
if (enable)
{
target.series.add(new IgrCrosshairLayer({ name: "crosshairLayer" }));
}
else
{
var toRemove = null;
for (var i = 0; i < target.actualSeries.length; i++) {
let s = target.actualSeries[i] as IgrSeries;
if (s instanceof IgrCrosshairLayer)
{
toRemove = s;
}
}
if (toRemove != null)
{
target.series.remove(toRemove);
}
}
break;
case "EnableFinalValues":
var enable = args.command.argumentsList[0].value as boolean;
if (enable)
{
target.series.add(new IgrFinalValueLayer({ name: "finalValueLayer" }));
}
else
{
var toRemove = null;
for (var i = 0; i < target.actualSeries.length; i++) {
let s = target.actualSeries[i] as IgrSeries;
if (s instanceof IgrFinalValueLayer)
{
toRemove = s;
}
}
if (toRemove != null)
{
target.series.remove(toRemove);
}
}
break;
}
}
}
// rendering above component in the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);
tsx
.aboveContentSplit {
display: flex;
flex-direction: row;
}
.aboveContentLeftContainer {
margin-left: 1.25rem;
display: flex;
flex-grow: 1;
justify-content: flex-start;
align-items: flex-end;
}
.aboveContentRightContainer {
margin-right: 1.25rem;
display: flex;
flex-grow: 1;
justify-content: flex-end;
align-items: flex-end;
}
css
React データ チャートの統合
React ツールバーには、Target
プロパティが含まれています。これは、以下のコードに示すように、IgrDataChart
などのコンポーネントをリンクするために使用されます。
private toolbar: IgrToolbar
private toolbarRef(r: IgrToolbar) {
this.toolbar = r;
this.setState({});
}
private chart: IgrDataChart
private chartRef(r: IgrDataChart) {
this.chart = r;
this.toolbar.target = this.chart;
this.setState({});
}
public render(): JSX.Element {
return (
<div>
<IgrToolbar
ref={this.toolbarRef}>
</IgrToolbar>
</div>
<div>
<IgrDataChart
ref={this.chartRef}>
</IgrDataChart>
</div>
);
}
tsx
IgrDataChart
が Toolbar にリンクされると、いくつかの既存の IgrToolAction
項目とメニューが使用可能になります。以下は、組み込みの React IgrDataChart
ツール操作とそれに関連付けられた overlayId
のリストです。
ズーム操作
トレンド操作
画像に保存アクション
SVG アイコン
ツールを手動で追加する場合、RenderIconFromText
メソッドを使用してアイコンを割り当てることができます。このメソッドには 3 つのパラメーターを渡す必要があります。1 つ目は、ツールで定義されたアイコン コレクション名です (例: iconCollectionName
)。2 つ目は、ツールで定義されたアイコンの名前 (例: iconName
) で、その後に SVG 文字列を追加します。
データ URL アイコン
svg を追加するのと同様に、RegisterIconFromDataURL
を介して URL からアイコン画像を追加することもできます。メソッドの 3 番目のパラメーターは、文字列 URL を入力するために使用されます。
次のスニペットは、アイコンを追加する両方の方法を示しています。
public toolbarCustomIconOnViewInit(): void {
const icon = '<svg width="28px" height="28px" stroke="none" viewBox="0 0 3.5 3.5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--gis" preserveAspectRatio="xMidYMid meet"><path d="M0.436 0.178a0.073 0.073 0 0 0 -0.062 0.036L0.01 0.846a0.073 0.073 0 0 0 0.063 0.109h0.729a0.073 0.073 0 0 0 0.063 -0.109L0.501 0.214a0.073 0.073 0 0 0 -0.064 -0.036zm0.001 0.219 0.238 0.413H0.199zM1.4 0.507v0.245h0.525v-0.245zm0.77 0v0.245h1.33v-0.245zM0.073 1.388A0.073 0.073 0 0 0 0 1.461v0.583a0.073 0.073 0 0 0 0.073 0.073h0.729A0.073 0.073 0 0 0 0.875 2.045V1.461a0.073 0.073 0 0 0 -0.073 -0.073zm0.073 0.146h0.583v0.438H0.146zM1.4 1.674v0.245h0.945v-0.245zm1.19 0v0.245h0.91v-0.245zM0.438 2.447c-0.241 0 -0.438 0.197 -0.438 0.438 0 0.241 0.197 0.438 0.438 0.438s0.438 -0.197 0.438 -0.438c0 -0.241 -0.197 -0.438 -0.438 -0.438zm0 0.146a0.291 0.291 0 0 1 0.292 0.292 0.291 0.291 0 0 1 -0.292 0.292 0.291 0.291 0 0 1 -0.292 -0.292A0.291 0.291 0 0 1 0.438 2.593zM1.4 2.842v0.245h0.525v-0.245zm0.77 0v0.245h1.33v-0.245z" fill="#000000" fill-rule="evenodd"/></svg>';
this.toolbar.registerIconFromText("CustomCollection", "CustomIcon", icon);
}
ts
public toolbarCustomIconOnViewInit(): void {
toolbar.registerIconFromDataURL("CustomCollection", "CustomIcon", "https://www.svgrepo.com/show/678/calculator.svg");
}
ts
public toolbarCustomIconOnViewInit(): void {
const icon = '<svg width="28px" height="28px" stroke="none" viewBox="0 0 3.5 3.5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--gis" preserveAspectRatio="xMidYMid meet"><path d="M0.436 0.178a0.073 0.073 0 0 0 -0.062 0.036L0.01 0.846a0.073 0.073 0 0 0 0.063 0.109h0.729a0.073 0.073 0 0 0 0.063 -0.109L0.501 0.214a0.073 0.073 0 0 0 -0.064 -0.036zm0.001 0.219 0.238 0.413H0.199zM1.4 0.507v0.245h0.525v-0.245zm0.77 0v0.245h1.33v-0.245zM0.073 1.388A0.073 0.073 0 0 0 0 1.461v0.583a0.073 0.073 0 0 0 0.073 0.073h0.729A0.073 0.073 0 0 0 0.875 2.045V1.461a0.073 0.073 0 0 0 -0.073 -0.073zm0.073 0.146h0.583v0.438H0.146zM1.4 1.674v0.245h0.945v-0.245zm1.19 0v0.245h0.91v-0.245zM0.438 2.447c-0.241 0 -0.438 0.197 -0.438 0.438 0 0.241 0.197 0.438 0.438 0.438s0.438 -0.197 0.438 -0.438c0 -0.241 -0.197 -0.438 -0.438 -0.438zm0 0.146a0.291 0.291 0 0 1 0.292 0.292 0.291 0.291 0 0 1 -0.292 0.292 0.291 0.291 0 0 1 -0.292 -0.292A0.291 0.291 0 0 1 0.438 2.593zM1.4 2.842v0.245h0.525v-0.245zm0.77 0v0.245h1.33v-0.245z" fill="#000000" fill-rule="evenodd"/></svg>';
this.toolbar.registerIconFromText("CustomCollection", "CustomIcon", icon);
}
ts
public toolbarCustomIconOnViewInit(): void {
toolbar.registerIconFromDataURL("CustomCollection", "CustomIcon", "https://www.svgrepo.com/show/678/calculator.svg");
}
ts
@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
var toolbar = this.toolbar;
if (firstRender) {
this.ToolbarCustomIconOnViewInit();
}
}
private IgbToolbar toolbar;
public void ToolbarCustomIconOnViewInit()
{
this.toolbar.EnsureReady().ContinueWith(new Action<Task>((e) =>
{
this.toolbar.RegisterIconFromDataURLAsync("CustomCollection", "CustomIcon", "https://www.svgrepo.com/show/678/calculator.svg");
}));
}
typescript
}
```tsx
<IgrToolbar orientation="Vertical" />
autohotkey
垂直方向
デフォルトでは、React ツールバーは水平に表示されますが、orientation
プロパティを設定することで垂直に表示することもできます。
<IgrToolbar orientation="Vertical" />
tsx
次の例は、React ツールバーの垂直方向を示しています。
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 { IgrToolbarModule } from "@infragistics/igniteui-react-layouts";
import { IgrDataChartToolbarModule, IgrDataChartCoreModule, IgrDataChartCategoryModule, IgrDataChartAnnotationModule, IgrDataChartInteractivityModule, IgrAnnotationLayerProxyModule, IgrDataChartCategoryTrendLineModule } from "@infragistics/igniteui-react-charts";
import { IgrToolbar } from "@infragistics/igniteui-react-layouts";
import { IgrDataChart, IgrCategoryXAxis, IgrNumericYAxis, IgrLineSeries } from "@infragistics/igniteui-react-charts";
import { CountryRenewableElectricityItem, CountryRenewableElectricity } from './CountryRenewableElectricity';
const mods: any[] = [
IgrToolbarModule,
IgrDataChartToolbarModule,
IgrDataChartCoreModule,
IgrDataChartCategoryModule,
IgrDataChartAnnotationModule,
IgrDataChartInteractivityModule,
IgrAnnotationLayerProxyModule,
IgrDataChartCategoryTrendLineModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private toolbar: IgrToolbar
private toolbarRef(r: IgrToolbar) {
this.toolbar = r;
this.setState({});
}
private chart: IgrDataChart
private chartRef(r: IgrDataChart) {
this.chart = r;
this.setState({});
}
private xAxis: IgrCategoryXAxis
private yAxis: IgrNumericYAxis
private lineSeries1: IgrLineSeries
constructor(props: any) {
super(props);
this.toolbarRef = this.toolbarRef.bind(this);
this.chartRef = this.chartRef.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="aboveContent">
<IgrToolbar
ref={this.toolbarRef}
target={this.chart}
orientation="Vertical">
</IgrToolbar>
</div>
<div className="container fill">
<IgrDataChart
isHorizontalZoomEnabled="true"
ref={this.chartRef}>
<IgrCategoryXAxis
name="xAxis"
dataSource={this.countryRenewableElectricity}
label="year">
</IgrCategoryXAxis>
<IgrNumericYAxis
name="yAxis"
title="TWh"
labelLocation="OutsideRight">
</IgrNumericYAxis>
<IgrLineSeries
name="lineSeries1"
title="Electricity"
xAxisName="xAxis"
yAxisName="yAxis"
dataSource={this.countryRenewableElectricity}
valueMemberPath="america">
</IgrLineSeries>
</IgrDataChart>
</div>
</div>
);
}
private _countryRenewableElectricity: CountryRenewableElectricity = null;
public get countryRenewableElectricity(): CountryRenewableElectricity {
if (this._countryRenewableElectricity == null)
{
this._countryRenewableElectricity = new CountryRenewableElectricity();
}
return this._countryRenewableElectricity;
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);
tsx
Color Editor (カラー エディター)
React Toolbar にカスタム カラー エディター ツールを追加できます。このツールは、コマンド イベントと連携して、アプリケーションにカスタム スタイルを適用することもできます。
<igc-toolbar
name="toolbar"
id="toolbar">
<igc-tool-action-color-editor
title="Series Brush Color"
name="colorEditorTool"
id="colorEditorTool">
</igc-tool-action-color-editor>
</igc-toolbar>
ts
<IgrToolbar
ref={this.toolbarRef}
target={this.chart}>
<IgrToolActionColorEditor
title="Series Brush Color"
name="colorEditorTool">
</IgrToolActionColorEditor>
</IgrToolbar>
tsx
次の例は、カラー エディター ツールを使用して React Data Chart シリーズ ブラシのスタイルを設定する方法を示しています。
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 { IgrToolbarModule, IgrToolActionComboModule, IgrToolActionColorEditorModule } from "@infragistics/igniteui-react-layouts";
import { IgrDataChartToolbarModule, IgrDataLegendModule, IgrNumberAbbreviatorModule, IgrDataChartCategoryModule, IgrDataChartCoreModule, IgrDataChartAnnotationModule, IgrDataChartInteractivityModule } from "@infragistics/igniteui-react-charts";
import { IgrToolbar, IgrToolActionColorEditor } from "@infragistics/igniteui-react-layouts";
import { IgrDataChart, IgrCategoryXAxis, IgrNumericYAxis, IgrLineSeries } from "@infragistics/igniteui-react-charts";
import { CountryRenewableElectricityItem, CountryRenewableElectricity } from './CountryRenewableElectricity';
import { IgrToolCommandEventArgs } from "@infragistics/igniteui-react-layouts";
import { IgrSeries } from "@infragistics/igniteui-react-charts";
const mods: any[] = [
IgrToolbarModule,
IgrToolActionComboModule,
IgrToolActionColorEditorModule,
IgrDataChartToolbarModule,
IgrDataLegendModule,
IgrNumberAbbreviatorModule,
IgrDataChartCategoryModule,
IgrDataChartCoreModule,
IgrDataChartCategoryModule,
IgrDataChartAnnotationModule,
IgrDataChartInteractivityModule,
IgrDataChartAnnotationModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private toolbar: IgrToolbar
private toolbarRef(r: IgrToolbar) {
this.toolbar = r;
this.setState({});
}
private colorEditorTool: IgrToolActionColorEditor
private chart: IgrDataChart
private chartRef(r: IgrDataChart) {
this.chart = r;
this.setState({});
}
private xAxis: IgrCategoryXAxis
private yAxis: IgrNumericYAxis
private lineSeries1: IgrLineSeries
constructor(props: any) {
super(props);
this.toolbarRef = this.toolbarRef.bind(this);
this.colorEditorToggleSeriesBrush = this.colorEditorToggleSeriesBrush.bind(this);
this.chartRef = this.chartRef.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="aboveContentSplit">
<div className="aboveContentLeftContainer">
<div>
<IgrToolbar
ref={this.toolbarRef}
target={this.chart}
onCommand={this.colorEditorToggleSeriesBrush}>
<IgrToolActionColorEditor
title="Series Brush"
name="colorEditorTool"
commandId="ToggleSeriesBrush">
</IgrToolActionColorEditor>
</IgrToolbar>
</div>
</div>
</div>
<div className="container fill">
<IgrDataChart
isHorizontalZoomEnabled="true"
ref={this.chartRef}>
<IgrCategoryXAxis
name="xAxis"
dataSource={this.countryRenewableElectricity}
label="year">
</IgrCategoryXAxis>
<IgrNumericYAxis
name="yAxis"
title="TWh"
labelLocation="OutsideRight">
</IgrNumericYAxis>
<IgrLineSeries
name="lineSeries1"
title="Electricity"
xAxisName="xAxis"
yAxisName="yAxis"
dataSource={this.countryRenewableElectricity}
valueMemberPath="america"
markerType="None">
</IgrLineSeries>
</IgrDataChart>
</div>
</div>
);
}
private _countryRenewableElectricity: CountryRenewableElectricity = null;
public get countryRenewableElectricity(): CountryRenewableElectricity {
if (this._countryRenewableElectricity == null)
{
this._countryRenewableElectricity = new CountryRenewableElectricity();
}
return this._countryRenewableElectricity;
}
public colorEditorToggleSeriesBrush(sender: any, args: IgrToolCommandEventArgs): void {
var target = this.chart;
switch (args.command.commandId)
{
case "ToggleSeriesBrush":
var color = args.command.argumentsList[0].value
var series = target.contentSeries[0] as IgrSeries;
series.brush = color as any;
break;
}
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);
tsx
.aboveContentSplit {
display: flex;
flex-direction: row;
}
.aboveContentLeftContainer {
margin-left: 1.25rem;
display: flex;
flex-grow: 1;
justify-content: flex-start;
align-items: flex-end;
}
.aboveContentRightContainer {
margin-right: 1.25rem;
display: flex;
flex-grow: 1;
justify-content: flex-end;
align-items: flex-end;
}
css
API リファレンス
その他のリソース