Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Date range

Read and set the dashboard date range from a Custom Metric widget — useUbidotsDashboardDateRange start/end and setDashboardDateRange startTime/endTime

GET

useUbidotsDashboardDateRange() returns the active dashboard date range. At runtime the host pushes it as { start, end }, in epoch ms. Read .start and .end.

EMIT (useUbidotsActions())

setDashboardDateRange({ startTime, endTime }) takes epoch ms numbers, with startTime < endTime. The action validates the range and ignores it if it's invalid.

How to implement: shift the range back one day

import { useUbidotsDashboardDateRange, useUbidotsActions } from '@ubidots/react-html-canvas';

function PreviousDay() {
  const range = useUbidotsDashboardDateRange(); // { start, end } epoch ms
  const { setDashboardDateRange } = useUbidotsActions();
  const back = () => {
    if (!range) return;
    const DAY = 86400000;
    setDashboardDateRange({ startTime: range.start - DAY, endTime: range.end - DAY });
  };
  return <button onClick={back}>Previous day</button>;
}

Last updated

Was this helpful?