Skip to main content

DXchart Optimizations

Prefetching chart data optimization

You can use extractDataRequests function for prefetch chart data optimization on initial loading. The request to data provider is made only after chart initialization (1-2 seconds), so in this case you might want to request data from server in advance. However, your data provider must implement caching mechanism, because when the chart will be initialized it will call the data provider for the data which should be already cached.

Here is an example of how you can use extractDataRequests function:

/* eslint-disable no-restricted-syntax */
import { ChartDataProvider } from '@dx-private/dxchart5-react/dist/providers/chart-data-provider';
import { ChartLayoutData } from '@dx-private/dxchart5-react/dist/providers/layout-provider';
import { extractDataRequests } from '@dx-private/dxchart5-react/dist/utils/extract-data-requests.util';
// these are just placeholders, you should replace them with your actual data provider and layout data
const chartDataProvider = {} as ChartDataProvider;
const layoutData = {} as ChartLayoutData;
const requests = extractDataRequests(layoutData);
requests.forEach(r => chartDataProvider.requestHistoryData(r.symbol, r.aggregation, r.options));