data-embed

A drop-in widget for aggregate data visualization. One script, three ways to embed, fully isolated in Shadow DOM.

01Quick Start

Include the script on any page. The widget renders inside a Shadow DOM, so its styles are fully isolated from yours.

<script src="data-embed.iife.js"></script>HTML

That's it. No build step, no framework dependencies, no CSS conflicts. Add a container element with one of three embed methods and the widget takes care of the rest.

02Embed Methods

A — Config from URL

Point data-embed at a JSON config file. The widget fetches and parses it automatically.

<div data-embed="/widget-config.json"></div>HTML

B — Inline JSON

Pass the full config object as the data-embed-inline attribute value. Useful when you want everything in one place.

<div data-embed-inline='{
  "dataUrl": "/data.json",
  "dimensions": ["state"],
  "metrics": [
    { "field": "id", "aggregation": "count", "label": "Total" }
  ]
}'></div>HTML

C — Programmatic

Call DataEmbed.mount() for full control. Pass a DOM element and a config object.

<div id="my-widget"></div>
<script>
  DataEmbed.mount(document.getElementById("my-widget"), {
    dataUrl: "/data.json",
    dimensions: ["state"],
    metrics: [
      { field: "id", aggregation: "count", label: "Total" }
    ]
  });
</script>JavaScript

03Configuration

Widget Config

PropertyTypeDescription
dataUrl required string URL to the JSON data file.
dimensions required string[] Initial fields to group by.
metrics required Metric[] Aggregations to compute per group. Multiple metrics appear as table columns; the chart plots the selected one.
dimensionOptions DimensionOption[] Restricts and labels the "Group by" dropdown. Each entry: a plain string or an object with field, label, and optional chartType.
title string Widget header title. Default: "Data Explorer"
chartType string Default chart type: column, bar, line, area, pie, stacked-bar, or stacked-column. Default: "column"
defaultView string "chart" or "table". Default: "chart"
height number Chart height in pixels. Default: 400
pageSize number Rows per page in the table. Default: 20
showTotals boolean Show a totals row in the table footer and a total badge in the header. Default: false

Metric Object

PropertyTypeDescription
field required string The data field to aggregate.
aggregation required string count, sum, avg, min, or max.
label string Display label for this metric. Auto-generated if omitted.

Full Example

{
  "dataUrl": "/data/optn_membership.json",
  "dimensions": ["organizationType"],
  "dimensionOptions": [
    { "field": "organizationType", "label": "Organization Type", "chartType": "pie" },
    { "field": "state", "label": "State", "chartType": "column" },
    { "field": "region", "label": "Region", "chartType": "column" }
  ],
  "metrics": [
    { "field": "centerCode", "aggregation": "count", "label": "Members" }
  ],
  "title": "OPTN Membership Data",
  "chartType": "column",
  "defaultView": "chart",
  "pageSize": 25,
  "showTotals": true
}JSON

04Data Format

The dataUrl endpoint should return JSON with a data array of flat objects. All keys become available as dimensions.

{
  "lastUpdated": "2026-06-05",
  "data": [
    {
      "region": 3,
      "centerCode": "ALCH",
      "organizationType": "Transplant Hospital",
      "state": "AL",
      "membershipStatus": "Approved"
    }
  ]
}JSON

lastUpdated is optional and displayed in the widget header when present.

05Live Demo

data-embed="widget-config.json"