← All articles

Chart Auto Refresh and Lazy Loading in Oracle APEX 26.2: the chartRegion API

APEX 26.2 documents a chartRegion interface with startAutoRefresh, stopAutoRefresh and a writable autoRefreshInterval, adds a chart Lazy Loading property and a ForegroundTimer class. Here is when a chart fetches its data, how auto refresh pauses itself, and the visibility gotcha to test after upgrading.

AI-readable summary

Oracle APEX 26.2 gives Chart regions a documented chartRegion interface, where charts previously relied on the generic region documentation. Auto refresh can be controlled from JavaScript: autoRefreshInterval is a writable number of seconds that starts from the Automatic Refresh: Interval attribute, must be 0 or at least 1, and should be much longer than the refresh request; startAutoRefresh starts refreshing and pauses while the browser window, tab or chart region is hidden, and stopAutoRefresh stops it. A new Performance: Lazy Loading property decides whether initial chart data is rendered with the page or requested with Ajax once the chart is first visible, and it stays enabled for existing applications. The manualLoading and lazyWhenIrrelevant options refine that. Lazy charts can display late on pages that toggle visibility outside Oracle's supported declarative techniques. A new apex.util.ForegroundTimer class runs your own polling only while the page is in the foreground, and Animation on Data Change now respects the reduced-motion preference.

The short version

Charts got a quiet but useful upgrade in APEX 26.2. The headline for builders is a documented chartRegion interface:

  • Auto refresh from code. Set autoRefreshInterval in seconds, call startAutoRefresh(), and stop with stopAutoRefresh().
  • It pauses itself. Refreshing pauses while the browser window, tab or chart region is hidden and resumes when it is visible again.
  • Lazy Loading. A new property decides whether the first data comes with the page or with an Ajax request once the chart is visible. It stays on for existing applications.
  • ForegroundTimer. A new apex.util.ForegroundTimer class gives your own polling the same pause-when-hidden behavior.
  • Accessibility. Animation on Data Change respects the operating system’s reduced-motion preference.

If you refresh several charts at once, our article on apex.region.multipleRefresh covers combining them into one request. This one is about when and how often a single chart talks to the server.

What changed in 26.2

The release notes group the work under Chart Enhancements. Chart refresh intervals get “new APIs to start, stop, and set the interval, together with more efficient foreground timer handling”, and resize and visibility handling “reduces unnecessary processing when charts are refreshed”. The JavaScript API updates add the ForegroundTimer class and a new chartRegion interface: “Previously, the Chart region relied on the generic region interface documentation.”

You get the interface the usual way, with apex.region and the region’s Static ID.

Auto refresh from JavaScript

The autoRefreshInterval property is writable. Its initial value comes from the chart’s Automatic Refresh: Interval attribute. Oracle’s example refreshes every five minutes while the chart is visible:

let chartRegion = apex.region( "myLineChart" );
chartRegion.autoRefreshInterval = 300; // 5 minutes
chartRegion.startAutoRefresh();

That makes a user-controlled live mode easy. A hypothetical example, run from a dynamic action when a P10_LIVE switch changes:

const chart = apex.region( "orders_chart" );
if ( $v( "P10_LIVE" ) === "Y" ) {
    chart.autoRefreshInterval = 120; // seconds
    chart.startAutoRefresh();
} else {
    chart.stopAutoRefresh();
}

The documented rules:

  • Valid values. “The value must be 0 (to disable auto refresh) or greater than or equal to 1.” The interval must not be 0 when you call startAutoRefresh().
  • Pausing. “The refreshing will pause if the browser window or tab or the chart region is hidden and will resume once it is visible again.”
  • Sizing. Small values such as 2 seconds “are discouraged since they may cause serious database performance issues”. The interval should be much longer than the refresh request takes. Oracle also says to take server resources and the expected number of clients into account.

That last point is the one we would underline. Every refresh is a query, multiplied by every open browser tab.

Code window with a hypothetical live switch that sets autoRefreshInterval to 120 seconds and calls startAutoRefresh or stopAutoRefresh, plus a ForegroundTimer with a 60 second interval. Beside it, a checklist of documented rules: 0 disables auto refresh, otherwise at least 1 second; refreshing pauses while the window, tab or chart is hidden and resumes when visible; the starting value comes from Automatic Refresh Interval; keep the interval far longer than the request; and small values such as 2 seconds are discouraged
A live mode in a few lines. The pause on hidden tabs comes for free.

Lazy Loading: when the first data arrives

The lazyLoading property is read only at runtime. Its value comes from the chart region’s Performance: Lazy Loading attribute, and the release notes say lazy loading “remains enabled by default for existing applications to preserve current behavior”. Oracle describes the two modes this way:

  • Off. “The initial chart data is generated by the server as part of the page and is shown as soon as the chart component is initialized.”
  • On. “The client will request the initial data using ajax as soon as the chart component is initialized.” The chart component is initialized when it is first visible.

Two options, set in the chart’s Initialization JavaScript Function, refine the lazy mode:

  • manualLoading. The chart does not fetch its initial data on its own, so your code can fetch several charts in one request. It only applies when Lazy Loading is on.
  • lazyWhenIrrelevant. The chart waits until it is scrolled into view, judged by the browser’s CSS content-visibility relevance, and auto refresh pauses while it is irrelevant. Oracle notes a small delay, likely under 100 ms, so use it for charts likely to start outside the viewport.
function( options ) {
    options.lazyWhenIrrelevant = true;
    return options;
}
Two by two grid of chart loading modes in APEX 26.2. Lazy Loading off: data is rendered with the page. Lazy Loading on, the default for existing apps: an Ajax request once the chart is first visible. Lazy Loading on with manualLoading: no automatic fetch, your code fetches, for example with apex.region.multipleRefresh. Lazy Loading on with lazyWhenIrrelevant: the chart waits until it is scrolled into view and auto refresh pauses while it is out of view
Four documented ways a chart gets its first data. Each marker shows when the data arrives.

The visibility gotcha

Lazy charts wait until they are visible to initialize and request data. The release notes warn that this “can impact initial chart display if your page controls chart visibility in ways other than the following supported declarative techniques”:

  • A Region Display Selector related to sibling regions, not child regions
  • A Static Content region with the Tabs Container template containing child regions
  • A Static Content region with the Collapsible template containing child regions
  • Show and Hide dynamic actions

If your page shows charts with its own JavaScript, for example a custom tab strip or a CSS class toggle, test the first display after upgrading. Two documented details help when you debug it: refresh() “does nothing if the chart control is not yet initialized”, and whenReady() returns a promise for when the chart is initialized. Oracle does not document a call to tell a lazy chart that custom code has made it visible, so the safest fix is moving that toggle to one of the supported techniques.

ForegroundTimer for your own polling

Charts are not the only thing that polls. apex.util.ForegroundTimer is “a controllable low resolution interval timer that runs only when the page is in the active or passive state (foreground)”. It pauses when the page is hidden, and it never calls the interval callback in less than the interval. Oracle’s example:

const t1 = new apex.util.ForegroundTimer( ( reason ) => {
        if ( reason === "interval" ) {
            console.log( "timer interval", new Date() );
            // do some processing
            // return false if something goes wrong and the timer needs to stop
        } else {
            console.log( "timer status change", reason );
        }
    }, {
        interval: 60,
        autoStart: true
    } );

The callback receives a reason: start, interval, pause, restart or stop. Returning false, or a promise that resolves to false, stops the timer, and a returned promise delays the next interval until it resolves. The timer has start, stop, pause, getState and destroy methods. Call destroy when you no longer need it, and note that minInterval defaults to 2 seconds.

Accessibility

One more change from the release notes: Animation on Data Change “now respects the operating system’s reduced-motion preference”. Users who ask their system for less motion now get chart updates that honor that setting, with no work on your side.

A short checklist

  • Charts toggled by custom JavaScript tested for first display after the upgrade
  • Lazy Loading reviewed on charts at the top of key pages
  • lazyWhenIrrelevant for charts far down long pages
  • Auto refresh intervals sized against query time and the number of open sessions
  • Live modes built with startAutoRefresh and stopAutoRefresh instead of hand-rolled setInterval
  • Custom polling moved to ForegroundTimer, with destroy on cleanup

Auto refresh multiplies database load by the number of open tabs, so it belongs on a platform you can watch. For managed APEX environments with monitoring, upgrades and support, see Cloud Hosting and the plans page.

Bottom line

The chartRegion interface turns chart auto refresh into a few documented calls, and the pause on hidden tabs means a forgotten dashboard stops querying the database. Lazy Loading makes the first fetch explicit, and manualLoading and lazyWhenIrrelevant give you control on busy pages.

The upgrade risk is narrow but real: charts shown by your own JavaScript. Test those first.

FAQ

How do I start and stop chart auto refresh from JavaScript?

Get the region with apex.region( "staticId" ), set autoRefreshInterval in seconds and call startAutoRefresh(). Call stopAutoRefresh() to stop.

Does auto refresh keep running in a background tab?

No. Oracle documents that refreshing pauses while the browser window, tab or chart region is hidden and resumes once it is visible again.

What is the minimum refresh interval?

The value must be 0, which disables auto refresh, or at least 1 second. Oracle discourages small values such as 2 seconds because of database load.

Is Lazy Loading on for my existing charts?

Yes. The release notes say lazy loading remains enabled by default for existing applications to preserve current behavior.

Why does my chart not show after I reveal it with my own code?

Lazy charts initialize when first visible, and Oracle lists only certain declarative techniques as supported. Move the toggle to a Region Display Selector, a Tabs Container or Collapsible template, or Show and Hide dynamic actions, then retest.

When should I use ForegroundTimer?

For your own periodic work in the browser, such as checking a status, when it should stop while the page is hidden and never run more often than the interval.

Sources