TX Sheet Control

Creating Dashboards

Topic

Dashboards are views of a workbook, based on data that is already in its worksheets. They share the document's persistence and authoring history with the worksheets, but display a canvas of their own. In code, you register worksheet data as an analytics source and add widgets or generate a starting dashboard. Saving the workbook as TXWB retains the dashboard definitions.

Bind Worksheet Data

A dashboard reads its data from a source. Create a table or a headed rectangular range, with clear field names and typed values, and register it as an analytics source. The following code registers a range of the first worksheet, adds a dashboard with one key metric and displays it. editor is the Spreadsheet of the browser editor, created as in JavaScript:

const book = editor.workbook;
const sheet = book.sheets.at(0);
book.analytics.setSource({
    id: 'sales', name: 'Sales', sheetId: sheet.id, range: 'A1:F25', hasHeaderRow: true
});

const dashboard = book.dashboards.add('Sales overview');
dashboard.addWidget({
    id: 'revenue', type: 'kpi', title: 'Total revenue',
    placement: { x: 0, y: 0, width: 4, height: 2 },
    query: { sourceId: 'sales', measures: [
        { field: 'Revenue', aggregation: 'SUM', alias: 'Revenue' }
    ] },
    format: { style: 'currency', currency: 'USD', maximumFractionDigits: 0 }
});

book.activeView = { type: 'dashboard', id: dashboard.id };

The code works as follows:

  • Workbook.analytics returns the DashboardAnalytics of the workbook. setSource registers the range A1:F25 of the first worksheet, identified by its id, as the source sales with a header row. Source IDs are unique.
  • Workbook.dashboards and DashboardCollection.add create an empty dashboard named Sales overview and return a Dashboard.
  • Dashboard.addWidget adds a key metric (type: 'kpi') with the ID revenue and the title Total revenue. placement positions the card on the dashboard grid, query sums the Revenue field of the source sales and format displays the result in US dollars without decimal places.
  • Workbook.activeView displays the new dashboard. Creating a dashboard never changes the displayed view by itself.

The example requires a Revenue header in the source range. An explicit range such as A1:F25 uses its header names as fields. Use a table binding instead when stable table-column identities are useful.

Generate a Starting Dashboard

Instead of adding each widget yourself, you can let the workbook propose a dashboard. book.dashboards.generate({ name: 'Sales overview' }) calls DashboardCollection.generate, which profiles the sources and creates an editable dashboard of at most 12 widgets with deterministic field-role rules.

Review the generated widgets and diagnostics before you present them as business reports:

  • Identifiers should not become summed amounts.
  • Prices and rates may require averages rather than totals.

Generation creates a new dashboard, unless you explicitly target an existing one with a supported merge or replace strategy. Business-specific field roles and templates can customize the result.

Query the Widgets

The query of a widget chooses its dimensions, measures, filters, relationships, sort and limits. Inspect the result of a widget through dashboard.query(widgetId), which calls Dashboard.query and evaluates that widget with the shared filters of the dashboard.

How the Layout and Persistence Work

The layout of a dashboard uses a responsive grid of 12 columns, not the A1 positions of a worksheet. Collisions relocate cards to open space.

TXWB and ODS persist the dashboard definitions, so save the workbook in one of these formats to keep them. TXWB is the native format; ODS keeps them in its TX workbook extension. Loading and Saving Workbooks shows how.

Create a Complete Sales Dashboard

The solution's Dashboard Performance sample uses 432 spreadsheet orders from two years. Its overview combines revenue, profit and unit KPIs, a forecast parameter, monthly revenue/profit, expandable regional summaries, customer drill-through and a monthly heatmap. Chart Gallery shows the additional chart families and Order Details displays the selected customer's orders. The Razor sample exposes it at /Dashboards; the JavaScript sample includes dashboards.html.

Create the same features through the public browser package @txtextcontrol/tx-sheet-control, its optional /angular entry point, the Node.js package @txtextcontrol/tx-sheet-control-server or the NuGet package TXTextControl.TXSheetControl.Server. ASP.NET Core editor integration remains in TXTextControl.TXSheetControl.AspNetCore. Dashboards based on spreadsheet sources require no database connector.

Table bindings use stable field IDs. Resolve them from a source profile rather than assuming a field ID equals its displayed caption:

const sheet = editor.workbook.sheets.at(0);
sheet.range('A1:D5').setValues([
    ['Region', 'Country', 'Revenue', 'Profit'],
    ['Europe', 'Germany', 42000, 12000],
    ['Europe', 'France', 38000, 9000],
    ['Americas', 'Canada', 31000, 8000],
    ['Americas', 'United States', 49000, 15000]
]);
sheet.tables.add('RegionalSales', 'A1:D5');
const book = editor.workbook;
const source = book.analytics.sources().find(item => item.name === 'RegionalSales')!;
const fields = Object.fromEntries(book.analytics.profile(source.id).fields.map(field => [field.name, field.id]));
const dashboard = book.dashboards.add('Regional Performance');
dashboard.applyTheme('light-2');
dashboard.addWidget({
    id: 'regions', type: 'column-stacked', title: 'Revenue and Profit by Region',
    placement: { x: 0, y: 0, width: 8, height: 6 },
    query: { sourceId: source.id, dimensions: [fields.Region], measures: [
        { field: fields.Revenue, aggregation: 'SUM', alias: 'Revenue' },
        { field: fields.Profit, aggregation: 'SUM', alias: 'Profit' }
    ] },
    chart: { axis: { minimum: 0, title: 'USD' }, labelPosition: 'inside' },
    appearance: { showDataLabels: true, animation: true },
    drillDown: [fields.Region, fields.Country],
    interactions: { action: 'expand' }
});
book.activeView = { type: 'dashboard', id: dashboard.id };

The table owns the source field identities; renaming a caption does not require replacing every widget. A range source registered with setSource instead uses the header names as IDs. The examples in the remaining guides use an explicit source named sales with matching header names.

Create and Export a Dashboard in .NET

Install TXTextControl.TXSheetControl.Server in your console or backend application. The server package includes the dashboard implementation, engine and fonts; it does not require the ASP.NET Core editor package. The following Program.cs creates two years of regional sales, compares revenue with the preceding year and exports both an editable workbook and a PDF.

using TXTextControl.TXSheetControl.Server;

await using var control = new ServerSheetControl();
var book = control.Workbook;
var sheet = await book.Sheets.AtAsync(0);
await sheet.Range("A1:D5").SetValuesAsync(new object?[][] {
    ["Date", "Region", "Revenue", "Profit"],
    ["2025-01-15", "Europe", 42000, 12000],
    ["2025-01-15", "Americas", 38000, 9000],
    ["2026-01-15", "Europe", 49000, 15000],
    ["2026-01-15", "Americas", 44000, 13000]
});
await book.Analytics.SetSourceAsync(new AnalyticsSource {
    Id = "sales", Name = "Regional Sales", SheetId = sheet.Id,
    Range = "A1:D5", HasHeaderRow = true
});
var dashboard = await book.Dashboards.AddAsync("Sales Performance");
await dashboard.ApplyThemeAsync("dark-1");
await dashboard.SetFiltersAsync([new AnalyticsFilter {
    SourceId = "sales", Field = "Date", Operator = "between",
    Values = ["2026-01-01", "2026-12-31"], DateGranularity = "day"
}]);
await dashboard.AddWidgetAsync(new DashboardWidget {
    Id = "revenue", Type = "kpi", Title = "Revenue Against Last Year",
    Placement = new() { X = 0, Y = 0, Width = 4, Height = 5 },
    Query = new() { SourceId = "sales", Measures = [
        new() { Field = "Revenue", Alias = "Revenue", Aggregation = "SUM" }
    ] },
    Kpi = new DashboardKpiSettings {
        Measure = "Revenue", Target = 100000,
        ComparisonPeriod = new() { Field = "Date", Unit = "year" }
    },
    Format = new() { Style = "currency", Currency = "USD", MaximumFractionDigits = 0 }
});
await dashboard.AddWidgetAsync(new DashboardWidget {
    Id = "regions", Type = "column", Title = "Revenue and Profit by Region",
    Placement = new() { X = 4, Y = 0, Width = 8, Height = 5 },
    Query = new() { SourceId = "sales", Dimensions = ["Region"], Measures = [
        new() { Field = "Revenue", Alias = "Revenue", Aggregation = "SUM" },
        new() { Field = "Profit", Alias = "Profit", Aggregation = "SUM" }
    ] },
    Chart = new DashboardChartSettings { Axis = new() { Minimum = 0, Title = "USD" } }
});
await control.SaveAsync("performance.txwb", StreamType.InternalWorkbookFormat);
await control.SaveAsync("performance.pdf", StreamType.PDF, new SaveOptions {
    Pdf = new PdfOptions { DashboardId = dashboard.Id, DashboardWidth = 1440 }
});

The current-period KPI is $93,000 and the comparison is $80,000. DashboardKpiSettings selects the baseline without changing source cells. DashboardChartSettings configures the numeric axis, while PdfOptions.DashboardId selects the dashboard instead of worksheet print pages. Configure a signed license before creating the control. PDF branding follows the license type and the editor or server export path.

The solution's .NET server sample adds a larger version through --dashboard. It writes a TXWB workbook, an SVG, a PDF and calculated KPI JSON. The Node.js sample at samples/server/dashboard.mjs uses the independent @txtextcontrol/tx-sheet-control-server package to export the same spreadsheet-backed overview as the browser showcase.

Open the Prepared Performance Workbook

Download the performance dashboard workbook to inspect the complete overview, chart gallery and customer-detail dashboard in an editor. The document includes 432 fictional orders and its saved settings, so it needs no database or external map service. The performance PDF shows the exported overview generated by the licensed server without a development notice.

Load the .txwb file with StreamType.InternalWorkbookFormat. Use design mode to inspect the widget queries and settings. Save as TXWB when you want to retain edits; XLSX stores the worksheet content and does not retain dashboard definitions.

Next Steps

  • Widgets: choose widget types, fields, aggregations and presentation settings.
  • Filters and Drill-Down: narrow the widgets with shared filters and drill hierarchies.
  • Dashboard Viewer: publish a dashboard in viewer mode.
  • Loading and Saving Workbooks: save the workbook as TXWB to keep its dashboards.
  • Tables: create the Excel-style tables that make stable dashboard sources.
  • Dashboards in Troubleshooting: find out why a widget is empty or an aggregate is wrong.