exportclassCategoryChartSharedData{
publicstatic generateItems(startValue: number, maxPoints: number, useShortLabels?: boolean): any[] {
const data: any[] = [];
let value = startValue;
for (let i = 0; i <= maxPoints; i++) {
value += Math.random() * 4.0 - 2.0;
const v = Math.round(value);
let l = i.toString();
if (useShortLabels) {
l = this.toShortString(i);
}
data.push({ Label: l, Value: v });
}
return data;
}
publicstatic getTemperatures(startValue: number, startYear: number, endYear: number): any[] {
const data: any[] = [];
let value = startValue;
for (let i = startYear; i <= endYear; i++) {
value += (Math.random() - 0.5) * 0.5;
const v = Math.abs(Math.round(value * 10) / 10);
data.push({ Label: i.toString(), Value: v });
}
return data;
}
publicstatic getLastItem(array: any[]): any {
if (array.length === 0) {
returnnull;
}
return array[array.length - 1];
}
publicstatic getNewItem(array: any[], index: number): any {
const lastItem = this.getLastItem(array);
const newValue = lastItem.Value + Math.random() * 4.0 - 2.0;
return { Label: index.toString(), Value: newValue };
}
publicstatic toShortString(largeValue: number): string {
let roundValue: number;
if (largeValue >= 1000000) {
roundValue = Math.round(largeValue / 100000) / 10;
return roundValue + "m";
}
if (largeValue >= 1000) {
roundValue = Math.round(largeValue / 100) / 10;
return roundValue + "k";
}
roundValue = Math.round(largeValue);
return roundValue + "";
}
publicstatic addDays(date: Date, days: number): Date {
date.setDate(date.getDate() + days);
return date;
}
}
ts
import { IgcCategoryChartModule } from'igniteui-webcomponents-charts';
import { IgcCategoryChartComponent } from'igniteui-webcomponents-charts';
import { ModuleManager } from'igniteui-webcomponents-core';
import { CategoryChartSharedData } from'./CategoryChartSharedData';
ModuleManager.register(IgcCategoryChartModule);
exportclassCategoryChartHighFrequency{
private chart: IgcCategoryChartComponent;
public dataIndex: number = 0;
public dataPoints: number = 100000;
public data: any[] = [];
public refreshMilliseconds: number = 10;
public interval: number = -1;
private dataInfoLabel: HTMLLabelElement;
private refreshInfoLabel: HTMLLabelElement;
private timerTickButton : HTMLButtonElement;
private shouldTick: boolean = false;
constructor() {
this.onRefreshFrequencyChanged = this.onRefreshFrequencyChanged.bind(this);
this.onDataGenerateClick = this.onDataGenerateClick.bind(this);
this.onTimerButtonClick = this.onTimerButtonClick.bind(this);
this.onDataPointsChanged = this.onDataPointsChanged.bind(this);
this.tick = this.tick.bind(this);
this.chart = document.getElementById('chart') as IgcCategoryChartComponent;
this.data = CategoryChartSharedData.generateItems(100, this.dataPoints, false);
this.chart.dataSource = this.data;
this.onChartInit();
let slider1 = document.getElementById('slider') as HTMLInputElement;
slider1.value = this.dataPoints.toString();
slider1!.addEventListener('change', this.onDataPointsChanged);
this.refreshInfoLabel = document.getElementById('refreshInfoLabel') as HTMLLabelElement;
this.refreshInfoLabel.textContent = (this.refreshMilliseconds / 1000).toFixed(3) + 's';
let refreshSlider = document.getElementById('refreshSlider') as HTMLInputElement;
refreshSlider.value = this.refreshMilliseconds.toString();
refreshSlider!.addEventListener('change', this.onRefreshFrequencyChanged);
this.dataInfoLabel = document.getElementById('dataInfoLabel') as HTMLLabelElement;
this.dataInfoLabel.textContent = CategoryChartSharedData.toShortString(this.dataPoints);
let dataGenerate1 = document.getElementById('dataGenerate') as HTMLInputElement;
dataGenerate1!.addEventListener('click', this.onDataGenerateClick);
this.timerTickButton = document.getElementById('timerButton') as HTMLButtonElement;
this.timerTickButton!.addEventListener('click', this.onTimerButtonClick);
}
publiccomponentWillUnmount() {
if (this.interval >= 0) {
window.clearInterval(this.interval);
this.interval = -1;
}
}
public onChartInit(): void {
this.setupInterval();
}
publiconDataGenerateClick() {
this.data = CategoryChartSharedData.generateItems(100, this.dataPoints, false);
this.dataIndex = this.data.length;
this.chart = document.getElementById('chart') as IgcCategoryChartComponent;
this.chart.dataSource = this.data;
}
publiconTimerButtonClick() {
this.shouldTick = !this.shouldTick;
if (this.shouldTick) {
this.timerTickButton.textContent = "Stop";
}
else {
this.timerTickButton.textContent = "Start";
}
}
public onDataPointsChanged = (e: any) => {
let num: number = parseInt(e.target.value, 10);
if (isNaN(num)) {
num = 10000;
}
if (num < 10000) {
num = 10000;
}
if (num > 1000000) {
num = 1000000;
}
const info = CategoryChartSharedData.toShortString(num);
this.dataInfoLabel.textContent = info;
this.dataPoints = num;
}
public onRefreshFrequencyChanged = (e: any) => {
let num: number = parseInt(e.target.value, 10);
if (isNaN(num)) {
num = 10;
}
if (num < 10) {
num = 10;
}
if (num > 500) {
num = 500;
}
this.refreshMilliseconds = num;
this.refreshInfoLabel.textContent = (this.refreshMilliseconds / 1000).toFixed(3) + 's';
this.setupInterval();
}
public setupInterval(): void {
if (this.interval >= 0) {
window.clearInterval(this.interval);
this.interval = -1;
}
this.interval = window.setInterval(() =>this.tick(),
this.refreshMilliseconds);
}
public tick(): void {
if (this.shouldTick) {
this.dataIndex++;
const oldItem = this.data[0];
const newItem = CategoryChartSharedData.getNewItem(this.data, this.dataIndex);
// updating data source and notifying category chartthis.data.push(newItem);
this.chart.notifyInsertItem(this.data, this.data.length - 1, newItem);
this.data.shift();
this.chart.notifyRemoveItem(this.data, 0, oldItem);
}
}
}
new CategoryChartHighFrequency();
ts
<!DOCTYPE html><html><head><title>CategoryChartHighFrequency</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /></head><body><divid="root"><divclass="container sample"><divclass="options horizontal"><labelclass="options-label">Refresh: </label><buttonid="timerButton">Start</button><labelclass="options-value"id="refreshInfoLabel"></label><inputclass="options-slider"id="refreshSlider"type="range"min="10"max="500"></input><buttonclass="options-button"id="dataGenerate">Generate</button><labelclass="options-label">Points: </label><labelclass="options-value"id="dataInfoLabel" >100000 </label><inputclass="options-slider"id="slider"type="range"min="10000"max="1000000"step="1000"value="100000"></input></div><igc-category-chartid="chart"chart-type="Line"width="100%"height="calc(100% - 3rem)"y-axis-extent="60"x-axis-enhanced-interval-prefer-more-category-labels="false"should-consider-auto-rotation-for-initial-labels="false"should-auto-expand-margin-for-initial-labels="false"crosshairs-display-mode="None"auto-margin-and-angle-update-mode="None"marker-types="None" ></igc-category-chart></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
このサンプルが気に入りましたか? 完全な Ignite UI for Web Componentsツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
exportclassCategoryChartSharedData{
publicstatic generateItems(startValue: number, maxPoints: number, useShortLabels?: boolean): any[] {
const data: any[] = [];
let value = startValue;
for (let i = 0; i <= maxPoints; i++) {
value += Math.random() * 4.0 - 2.0;
const v = Math.round(value);
let l = i.toString();
if (useShortLabels) {
l = this.toShortString(i);
}
data.push({ Label: l, Value: v });
}
return data;
}
publicstatic getTemperatures(startValue: number, startYear: number, endYear: number): any[] {
const data: any[] = [];
let value = startValue;
for (let i = startYear; i <= endYear; i++) {
value += (Math.random() - 0.5) * 0.5;
const v = Math.abs(Math.round(value * 10) / 10);
data.push({ Label: i.toString(), Value: v });
}
return data;
}
publicstatic getLastItem(array: any[]): any {
if (array.length === 0) {
returnnull;
}
return array[array.length - 1];
}
publicstatic getNewItem(array: any[], index: number): any {
const lastItem = this.getLastItem(array);
const newValue = lastItem.Value + Math.random() * 4.0 - 2.0;
return { Label: index.toString(), Value: newValue };
}
publicstatic toShortString(largeValue: number): string {
let roundValue: number;
if (largeValue >= 1000000) {
roundValue = Math.round(largeValue / 100000) / 10;
return roundValue + "m";
}
if (largeValue >= 1000) {
roundValue = Math.round(largeValue / 100) / 10;
return roundValue + "k";
}
roundValue = Math.round(largeValue);
return roundValue + "";
}
publicstatic addDays(date: Date, days: number): Date {
date.setDate(date.getDate() + days);
return date;
}
}
ts
import { IgcCategoryChartModule } from'igniteui-webcomponents-charts';
import { IgcCategoryChartComponent } from'igniteui-webcomponents-charts';
import { ModuleManager } from'igniteui-webcomponents-core';
import { CategoryChartSharedData } from'./CategoryChartSharedData';
ModuleManager.register(IgcCategoryChartModule);
exportclassCategoryChartHighVolume{
private chart: IgcCategoryChartComponent;
public dataPoints: number = 500000;
public dataInfo: string = CategoryChartSharedData.toShortString(this.dataPoints);
public data: any[] = [];
private dataInfoLabel: HTMLLabelElement;
constructor() {
this.onDataPointsChanged = this.onDataPointsChanged.bind(this);
this.onDataGenerateClick = this.onDataGenerateClick.bind(this);
this.chart = document.getElementById('chart') as IgcCategoryChartComponent;
this.chart.dataSource = CategoryChartSharedData.generateItems(0, this.dataPoints, true);
let slider1 = document.getElementById('dataPointsSlider') as HTMLInputElement;
slider1!.addEventListener('change', this.onDataPointsChanged);
let DataGenerate1 = document.getElementById('DataGenerate') as HTMLButtonElement;
DataGenerate1!.addEventListener('click', this.onDataGenerateClick);
}
public onDataPointsChanged = (e: any) => {
this.dataPoints = e.target.value;
const info = CategoryChartSharedData.toShortString(this.dataPoints);
this.dataPoints = this.dataPoints;
this.dataInfo = info;
this.dataInfoLabel = document.getElementById('dataInfoLabel') as HTMLLabelElement;
this.dataInfoLabel.textContent = this.dataPoints.toString();
}
public onDataGenerateClick = (e: any) => {
if (this.dataPoints === undefined) {
this.dataPoints = 10000;
}
this.generateData();
}
publicgenerateData() {
this.chart.dataSource = CategoryChartSharedData.generateItems(0, this.dataPoints, true);
}
}
new CategoryChartHighVolume();
ts
<!DOCTYPE html><html><head><title>CategoryChartHighVolume</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /></head><body><divid="root"><divclass="container sample"><divclass="options horizontal"><labelclass="options-label">Data Points: </label><labelclass="options-value"id="dataInfoLabel"> 500000 </label><inputid="dataPointsSlider"class="options-slider"type="range"min="10000"max="1000000"step="1000"value=500000 /><buttonid="DataGenerate">Generate Data</button></div><igc-category-chartid="chart"width="100%"height="calc(100% - 3rem)"chart-type="Line"tool-tip-type="Default"y-axis-extent="60"x-axis-enhanced-interval-prefer-more-category-labels="false"should-consider-auto-rotation-for-initial-labels="false"should-auto-expand-margin-for-initial-labels="false"crosshairs-display-mode="None"auto-margin-and-angle-update-mode="None"marker-types="None" ></igc-category-chart></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
凡例を Web Components チャートに追加すると、凡例にマップされたシリーズまたはデータ項目のタイトルが実行時に頻繁に変更される場合、パフォーマンスが低下する可能性があります。
チャート マーカー
Web Components チャートでは、チャート マーカーはチャートのレイアウトの複雑さを増し、特定の情報を取得するためにデータ バインディングを実行するため、チャートのパフォーマンスに関しては特に手間がかかります。また、データ ポイントが多い場合、またはバインドされているデータ ソースが多い場合、マーカーはパフォーマンスを低下させます。したがって、マーカーが不要な場合は、チャートから削除する必要があります。
以下のコード例は、Web Components チャートからマーカーを削除する方法を示します。
// on CategoryChart or FinancialChartthis.Chart.markerTypes.clear();
this.Chart.markerTypes.add(MarkerType.None);
// on LineSeries of DataChartthis.LineSeries.markerType = MarkerType.None;
ts
データ ポイント間の時間間隔に基づくスペースが重要でない場合は、DateTime をサポートする x 軸の使用はお勧めしません。代わりに、順序/カテゴリ軸を使用する必要があります。これは、データを結合する方法がより効率的であるためです。また、順序/カテゴリ軸は、時間ベースの x 軸のようにデータのソートを実行しません。
<igc-category-charty-axis-title="In millions of Dollars"></igc-category-chart><igc-financial-charty-axis-title="In millions of Dollars"></igc-financial-chart><igc-data-chart><igc-numeric-y-axistitle="In millions of Dollars"></igc-numeric-y-axis></igc-data-chart>html