DashboardAnalytics Class
Workbook-wide analytics; caches are private, column-oriented and invalidated by affected cells and formula changes.
Package: @txtextcontrol/tx-sheet-control-server. Version: 2.0.0.
Related workbook object-model type, returned through the server control. Obtain it from its owning workbook or collection; it is not a required browser-package import.
Members
Methods
| Method | Description |
|---|---|
| data | Returns at most 1,000 source rows after filters; application must authorize source-data access per widget. |
| profile | Profiles up to 250,000 cells per source. Call after before-events complete; returns detached metadata and diagnostics. |
| query | Executes without UI, yielding every 2,048 rows. Rejects cancellation, stale snapshots and ambiguous joins. |
| refresh | Refreshes source columns/aggregates and requests live data through dataRefreshRequested. Does not await providers. |
| relationships | Lists only explicitly established many-to-one relationships. No automatic join is applied. |
| removeRelationship | Removes a join definition without rewriting user queries. Those queries report a missing relationship. |
| removeSource | Removes an explicit binding; dependent widgets display a missing-source diagnostic. |
| setData | Replaces a connector source's transient snapshot atomically after validation. Rows are detached, bounded to 250,000 cells and cleared on document replacement. Existing queries, joins and widgets use the same field IDs as worksheet sources. |
| setRelationship | Validates target uniqueness before saving an explicit relationship. Blanks never match blank keys. |
| setSource | Registers a range/table or logical connector binding. IDs are unique; replacement invalidates its cache. |
| sources | Discovers Excel tables and rectangular named ranges across all worksheets, plus explicit API bindings. |
| suggestRelationships | Suggests same-name key joins only with unique target keys and at least 90% observed source coverage. |
Examples
Use a fresh workbook. Create and format the sample data, apply this API and retain the returned document or result in your application. In the browser pass editor.workbook; in Node.js pass the server control.
import type { ServerSheetControl } from '@txtextcontrol/tx-sheet-control-server';
function createDashboardAnalyticsReport(control: ServerSheetControl) {
const book = control.workbook;
const sheet = book.sheets.at(0);
sheet.range('A1:B5').setValues([
['Region', 'Revenue'],
['North', 42000],
['South', 38500],
['East', 31200],
['West', 44900],
]);
book.analytics.setSource({
id: 'sales',
name: 'Regional sales',
sheetId: sheet.id,
range: 'A1:B5',
hasHeaderRow: true,
});
const dashboard = book.dashboards.add('Sales overview');
dashboard.addWidget({
id: 'revenue',
type: 'bar',
title: 'Revenue by region',
placement: { x: 0, y: 0, width: 6, height: 4 },
query: {
sourceId: 'sales',
dimensions: ['Region'],
measures: [{ field: 'Revenue', aggregation: 'SUM', alias: 'Revenue' }],
},
drillDown: ['Region'],
interactions: { filter: true, allowSourceData: true },
});
return dashboard.snapshot;
}