@@ -13,7 +13,7 @@ Embedded Chart Options
13
13
:class: singlecol
14
14
15
15
You can customize the appearance and behavior your embedded charts with a
16
- variety of options. Options are avaiable to charts charts embedded with the
16
+ variety of options. Options are available to charts charts embedded with the
17
17
:ref:`Embedding SDK <embedding-charts-sdk>` and embedded within :ref:`iframes
18
18
<embedding-charts-iframe>`.
19
19
@@ -49,8 +49,7 @@ variety of options. Options are avaiable to charts charts embedded with the
49
49
chartId: "8d4dff93-e7ca-4ccd-a622-e20e8a100197",
50
50
baseUrl: "https://charts.mongodb.com/charts-embedding-examples-hmewt",
51
51
height: 300,
52
- width: 400,
53
- refreshInterval: 300
52
+ width: 400
54
53
});
55
54
56
55
The following options are available to ``createChart``:
@@ -93,10 +92,27 @@ variety of options. Options are avaiable to charts charts embedded with the
93
92
- A :ref:`filter <embed-options-filter>` to apply to the chart.
94
93
- no
95
94
96
- * - ``refreshInterval``
95
+ * - ``autoRefresh``
96
+ - boolean
97
+ - Specifies whether the chart automatically refreshes. If
98
+ omitted, charts do not automatically refresh.
99
+
100
+ Use this option with the ``maxDataAge`` option to
101
+ configure how often the chart refreshes.
102
+ - no
103
+
104
+ * - ``maxDataAge``
97
105
- number
98
- - How often to refresh the chart, in seconds. The minimum refresh
99
- interval is 10 seconds. ``autorefresh`` is off by default.
106
+ - Specifies the maximum age of data to load from the cache
107
+ when loading or refreshing the chart. If omitted,
108
+ |charts| renders the chart with data from the cache if
109
+ the data is less than one hour old.
110
+
111
+ To learn how |charts| loads data from the cache when
112
+ loading or refreshing the chart based on the
113
+ ``autoRefresh`` and ``maxDataAge`` values, see
114
+ :ref:`auto-refresh-behavior`.
115
+
100
116
- no
101
117
102
118
* - ``theme``
@@ -164,12 +180,14 @@ variety of options. Options are avaiable to charts charts embedded with the
164
180
.. example::
165
181
166
182
The following code snippets set the theme of a Chart instance named
167
- ``chart`` to ``dark`` and its refresh interval to 30 seconds.
183
+ ``chart`` to ``dark`` and it to refresh automatically every
184
+ 30 seconds.
168
185
169
186
.. code-block:: javascript
170
187
171
188
chart.setTheme("dark");
172
- chart.setRefreshInterval(30);
189
+ chart.setAutoRefresh(true);
190
+ chart.setMaxDataAge(30);
173
191
174
192
.. list-table::
175
193
:header-rows: 1
@@ -178,9 +196,23 @@ variety of options. Options are avaiable to charts charts embedded with the
178
196
* - Method
179
197
- Description
180
198
181
- * - ``setRefreshInterval(seconds: number)``
182
- - Sets how long the embedded chart waits before refreshing.
183
- The minimum interval is 10 seconds. To disable, set to 0.
199
+ * - ``setAutoRefresh``
200
+ - Specifies whether the chart automatically refreshes. If
201
+ omitted, charts do not automatically refresh.
202
+
203
+ Use this method with the ``setMaxDataAge`` method to
204
+ configure how often the chart refreshes.
205
+
206
+ * - ``setMaxDataAge``
207
+ - Specifies the maximum age of data to load from the cache
208
+ when loading or refreshing the chart. If omitted,
209
+ |charts| renders the chart with data from the cache if
210
+ the data is less than one hour old.
211
+
212
+ To learn how |charts| loads data from the cache when
213
+ loading or refreshing the chart based on the
214
+ ``setAutoRefresh`` and ``setMaxDataAge`` values, see
215
+ :ref:`auto-refresh-behavior`.
184
216
185
217
* - ``setFilter(filter: object)``
186
218
- Applies a :ref:`query filter <filter-embedded-charts>` to the
@@ -197,7 +229,7 @@ variety of options. Options are avaiable to charts charts embedded with the
197
229
- Sets the current theme of the embedded chart. When setting the
198
230
theme to ``dark``, you need to ensure that your chart's
199
231
background color has appropriate contrast so that the information
200
- remains visible. By default, a chart's background is transparent.
232
+ remains visible.
201
233
202
234
.. seealso::
203
235
@@ -217,58 +249,75 @@ variety of options. Options are avaiable to charts charts embedded with the
217
249
specify a refresh interval for your chart, as well as a light or
218
250
dark display theme.
219
251
220
- Specify a Refresh Interval
221
- --------------------------
252
+ Configure Auto Refresh and Data Caching Behavior
253
+ ------------------------------------------------
254
+
255
+ Use the ``autorefresh`` query parameter to configure the chart
256
+ to refresh automatically.
222
257
223
- Use the ``autorefresh`` query parameter to define the interval,
224
- in seconds, at which the chart refreshes with the latest data from
225
- its :ref:`data source <data-sources>`. Use the options on the
226
- :guilabel:`Unauthenticated` tab on the :guilabel:`Embed Chart` dialog
227
- to customize the ``autorefresh`` value in the iframe snippet.
258
+ Use the ``maxDataAge`` query parameter to:
228
259
229
- If you do not specify the ``autorefresh`` option, your embedded chart
230
- loads once when the iframe loads and does not automatically refresh.
260
+ - Determine the interval at which the chart refreshes if
261
+ ``autorefresh`` is ``true``.
262
+ - Configure the maximum age of data to load from the cache when
263
+ loading or manually refreshing the chart if ``autorefresh``
264
+ is ``false`` or omitted.
265
+
266
+ To learn how |charts| loads data from the cache when loading
267
+ or refreshing the chart based on the ``autorefresh`` and
268
+ ``maxDataAge`` values, see :ref:`auto-refresh-behavior`.
269
+
270
+ Use the options on the
271
+ :guilabel:`Unauthenticated` tab on the :guilabel:`Embed Chart`
272
+ dialog to customize the ``autorefresh`` value in the iframe
273
+ snippet.
231
274
232
275
Example
233
276
~~~~~~~
234
277
235
- The following iframe embeds a chart which automatically refreshes
236
- every 30 seconds as defined by the ``autorefresh=30`` query parameter:
278
+ The following iframe embeds a chart which automatically
279
+ refreshes every 30 seconds as defined by the
280
+ ``autorefresh=true`` and the ``maxDataAge=30`` query
281
+ parameters:
237
282
238
283
.. code-block:: html
239
284
240
285
<iframe style="border: none;border-radius: 2px;box-shadow: 0 2px
241
286
10px 0 rgba(70, 76, 79, .2);" width="640" height="480" src="
242
287
{charts-host}/embed/charts?id=b3ca720f-4b4a-40b4-a726-e7dc0c49aa1c&
243
- autorefresh=30"></iframe>
288
+ autorefresh=true&maxDataAge= 30"></iframe>
244
289
245
290
Considerations
246
291
~~~~~~~~~~~~~~
247
292
248
- - The minimum automatic refresh interval is 10 seconds. If you specify
249
- an ``autorefresh `` value less than 10, the chart refreshes every 10
250
- seconds.
293
+ - The minimum cache duration is 10 seconds. If ``autorefresh``
294
+ is ``true `` and you specify a ``maxDataAge`` value less than
295
+ 10, the chart refreshes every 10 seconds.
251
296
252
- - If you specify an ``autorefresh`` value which is not an integer or
253
- less than 0, an :ref:`error <embedded-errors>` is returned.
297
+ - If you specify an ``maxDataAge`` value which is not an
298
+ integer or less than ``-1``, an :ref:`error
299
+ <embedded-errors>` is returned.
254
300
255
301
- If your data source requires a
256
- :ref:`Verified Signature <embed-with-iframe-procedure>`, the signature
257
- validity (including the expiry date) is checked on each refresh. If
258
- the signature's expiry date passed, the host web page must
259
- regenerate a new signature to continue rendering charts. For
260
- code examples using verified signatures, see
261
- `MongoDB Charts Embedding Examples <https://github.com/mongodb/charts-embedding-examples>`__
302
+ :ref:`Verified Signature <embed-with-iframe-procedure>`, the
303
+ signature validity (including the expiry date) is checked on
304
+ each refresh. If the signature's expiry date passed, the host
305
+ web page must regenerate a new signature to continue
306
+ rendering charts. For code examples using verified
307
+ signatures, see
308
+ `MongoDB Charts Embedding Examples
309
+ <https://github.com/mongodb/ charts-embedding-examples>`__
262
310
on GitHub.
263
311
264
312
.. example::
265
313
266
- If you specify an automatic refresh interval of one minute and the
267
- expiry date of the signature is in 1 hour, the chart refreshes
268
- every minute for an hour. Once one hour has elapsed, the chart
269
- will not render and an error will be displayed as the signature is
270
- no longer valid. The host web page must regenerate a new signature
271
- to resume rendering the chart.
314
+ If ``autorefresh`` is ``true``, the cache duration is one
315
+ minute (``maxDataAge=60``), and the expiry date of the
316
+ signature is in one hour, the chart refreshes every minute
317
+ for an hour. Once one hour has elapsed, the chart will not
318
+ render and an error will be displayed as the signature is
319
+ no longer valid. The host web page must regenerate a new
320
+ signature to resume rendering the chart.
272
321
273
322
Specify a Display Theme
274
323
-----------------------
@@ -323,9 +372,17 @@ variety of options. Options are avaiable to charts charts embedded with the
323
372
<https://developer.mozilla.org/en-US/docs/Web/CSS/background>`__
324
373
in the MDN Web Docs for more information.
325
374
326
- - Remove the ``background`` property to display the chart with a
327
- transparent background, allowing your application's background to
375
+ - Change the ``background`` property to ``transparent`` to
376
+ display the chart with a transparent background, allowing
377
+ your application's background to
328
378
display through the chart.
379
+
380
+ - Remove the ``background`` property to use the default
381
+ background color of the theme you choose:
382
+
383
+ - ``#FFFFFF`` for the ``light`` theme (default), or
384
+
385
+ - ``#21313C`` for the ``dark`` theme.
329
386
330
387
Chart Border
331
388
~~~~~~~~~~~~
@@ -413,4 +470,32 @@ variety of options. Options are avaiable to charts charts embedded with the
413
470
theme=light&
414
471
attribution=false
415
472
"></iframe>
416
-
473
+
474
+ .. _auto-refresh-behavior:
475
+
476
+ Auto Refresh and Data Caching Behavior
477
+ --------------------------------------
478
+
479
+ The following table describes how |charts| loads data from the cache
480
+ when loading or refreshing the chart based on the ``autorefresh`` or
481
+ ``autoRefresh`` and ``maxDataAge`` values.
482
+
483
+ .. note::
484
+
485
+ The casing of the ``autoRefresh`` option differs based on whether
486
+ you embed a chart using the Embedding SDK or an iframe:
487
+
488
+ .. list-table::
489
+ :header-rows: 1
490
+ :widths: 50 50
491
+
492
+ * - Embedding Method
493
+ - Auto Refresh Option
494
+
495
+ * - Embedding SDK
496
+ - ``autoRefresh``
497
+
498
+ * - iframe
499
+ - ``autorefresh``
500
+
501
+ .. include:: /includes/autorefresh-maxdataage-values.rst
0 commit comments