Docs

Get started

Standalone charts

Draw one chart from rows and a config, with no workspace around it.

Quick start

Use Chart from exploreda/chart when you want explorEDA's charts in your own React layout, without the workspace. Give it rows and a config, and it draws one chart. There is no toolbar, no grid, and no filtering between charts.

To find the config for your chart, open the Chart builder: pick a chart type, paste your own rows, change settings, and copy the code.

Terminal
pnpm add exploreda
Loading charts…
TSX
import { Chart } from "exploreda/chart";
import "exploreda/dist/chart.css";

const rows = [
  { Region: "West", Price: 12, Rating: 4.1 },
  { Region: "East", Price: 9, Rating: 3.8 },
  // …
];

export function SalesCharts() {
  return (
    <div style={{ display: "flex", flexWrap: "wrap", gap: 16 }}>
      <div style={{ flex: "1 1 280px" }}>
        <Chart data={rows} config={{ type: "bar", field: "Region" }} height={260} />
      </div>
      <div style={{ flex: "1 1 280px" }}>
        <Chart
          data={rows}
          config={{ type: "scatter", xField: "Price", yField: "Rating" }}
          height={260}
        />
      </div>
    </div>
  );
}

Each Chart is independent. Put as many on a page as you need, in any layout.

The config

A config is the chart's type plus the settings that differ from that type's defaults. Every setting you leave out takes the same default as a new chart in the workspace.

TSX
<Chart data={rows} config={{ type: "bar", field: "Region" }} />
<Chart data={rows} config={{ type: "line", xField: "Date", seriesField: ["Units"] }} />
<Chart
  data={rows}
  config={{ type: "scatter", xField: "Price", yField: "Rating", colorField: "Region" }}
/>

Setting names are the names the workspace saves. Each chart's page lists every setting of that type, with its default, under Saved settings. For example, see Bar chart and Scatter plot. The gallery at the end of this page links each chart type to its list.

  • ChartConfig is typed per chart type, so your editor completes the settings of the type you set.
  • A colorField is enough to color a chart. Chart picks the color scale that the workspace would pick.
  • A config that is missing a setting the type needs, such as a scatter plot without yField, shows the chart's own empty message.

Dashboard text

config also takes one chart's Dashboard text: the same line that builds that chart in a dashboard.

Loading charts…
  • A line can use what Dashboard text offers, such as sum(Units) or a calculated field, and the chart keeps it.
  • A line that builds no chart shows the compiler's message in place of the chart.
  • After an edit, onConfigChange gives the object form. Store that, or keep the text and leave editing off.

Props

data
The rows to draw, one object per row. Pass a new array when rows change.
config
The chart type and any settings that differ from its defaults, such as { type: "bar", field: "Region" }. Setting names are the saved names each chart's page lists.
title
The heading above the plot. By default it is config.title, or a name built from the chart's fields. Pass false to hide it.
width
Width in pixels. Without it, the chart fills the width of its parent.
height
Height in pixels, heading included. Without it, the chart fills the height of its parent, or takes 300 px when the parent has no height.
onConfigChange
Called after each edit with the short config: the type, its main field, and only the settings that differ from the defaults. Passing it turns editing on: the settings button, and edits inside the chart such as a note's text. The chart is controlled, so an edit shows only once you pass the new config back as config.
fields
The fields that settings offer, such as ["Region", "Price"]. Fields the config already uses stay available. Without it, settings offer every field in data.
settingsButton
Shows the settings button when editing is on. Pass false to edit only through a ChartSettings you place yourself.
className
A class for the chart's outer element.
style
Inline styles for the chart's outer element.

What a reader can do

  • Hover: tooltips and hover readouts work as in the workspace.
  • Click and brush: nothing is selected. A standalone chart has no filter state.
  • Edit: only when you pass onConfigChange.

Edit settings at runtime

Pass onConfigChange to let readers change a chart's settings. The chart shows a settings button that opens the same settings the workspace uses. Each edit calls onConfigChange with the new config in its short form: the type, its main field, and only the settings that differ from the defaults.

The chart is controlled, like a React <input value>: an edit shows only once you pass the new config back as config. Keep the config in state, and the chart and your state never disagree. Leave onConfigChange out, and the chart is read-only.

To put the settings somewhere else, such as a sidebar, place a ChartSettings with the same data and config, and pass its onConfigChange result to both. Pass settingsButton={false} to hide the chart's own button.

Loading charts…
TSX
import { Chart, ChartSettings, type ChartConfig } from "exploreda/chart";
import { useState } from "react";

export function EditableChart({ rows }) {
  const [config, setConfig] = useState<ChartConfig>({
    type: "scatter",
    xField: "Price",
    yField: "Rating",
  });
  return (
    <div style={{ display: "flex", flexWrap: "wrap", gap: 16 }}>
      {/* The gear opens settings; each edit comes back through setConfig. */}
      <div style={{ flex: "1 1 320px" }}>
        <Chart data={rows} config={config} onConfigChange={setConfig} height={300} />
      </div>
      {/* Or place the same settings yourself, bound to the same state. */}
      <ChartSettings
        data={rows}
        config={config}
        onConfigChange={setConfig}
        fields={["Region", "Product", "Price", "Rating", "Units"]}
        style={{ flex: "0 1 21rem" }}
      />
    </div>
  );
}

Try the gear on the chart, or the panel beside it: both edit the same state. The panel offers only the five fields listed in fields.

  • The short config draws exactly the same chart, so store it as it is.
  • A color scale picked for a colorField is not part of the config. The chart picks the workspace's default scale again each time.
  • Settings that need the workspace, such as filters and calculated fields, have no effect on a standalone chart.

ChartSettings props

data
The same rows as the chart. Settings read them to list fields and values.
config
The same config as the chart.
onConfigChange
Called after each edit with the short config. Store it and pass it to both the chart and the panel.
fields
The fields the panel offers, as for Chart.
className
A class for the panel's outer element.
style
Inline styles for the panel's outer element.

Styles

Import exploreda/dist/chart.css once. It styles only the charts:

  • It has no global reset. Your page's buttons, headings, and fonts stay as they are.
  • Its theme variables, such as --background and --primary, sit on each chart's element, not on :root. A host that uses the same names keeps its own values.
  • Your page's element rules, such as a page-wide button {} style, do not restyle the chart's own controls.
  • Text in a chart takes your page's font, as the workspace does.
  • Tooltips, menus, and popovers mount inside the chart's element, so the same styles reach them.

Size

  • Pass width and height to set the size in pixels.
  • Leave them out to fill the parent element. Give the parent a height, or the chart takes 300 px.
  • height includes the title line. Pass title={false} to give all of it to the plot.

Load only the charts you use

exploreda/chart loads each chart type's code the first time a chart of that type draws. A page with a bar chart never downloads the 3D scatter or the note editor. Until a type's code arrives, which is one small request, the chart holds its box.

Two things load every type, because they can name any type:

  • A ChartSettings panel or a settings button, once it opens, so its Chart Type list is complete.
  • A Dashboard text config.

To have no request at all before a chart draws, import from exploreda/chart-core and register the types up front:

TSX
import { Chart, registerCharts } from "exploreda/chart-core";
import { barChartDefinition } from "exploreda/charts/bar";
import { scatterPlotDefinition } from "exploreda/charts/scatter";
import "exploreda/dist/chart.css";

registerCharts(barChartDefinition, scatterPlotDefinition);

<Chart data={rows} config={{ type: "bar", field: "Region" }} />;
  • Call registerCharts once, before the first chart draws, such as at the top of the module.
  • With chart-core, a chart whose type isn't registered shows the two lines to add in its place.
  • Map shapes load only when a map draws, with either entry.

What the example app's pages load up front, React included:

PageEntryUp front
34 charts covering all 27 types, with settings and a text configexploreda/chart1,283 KB, the rest after first paint
A bar chart and a scatter plotexploreda/chart-core1,425 KB
The first page, before types loaded on demandexploreda/chart2,987 KB
ChartImport fromDefinition
Scatter plotexploreda/charts/scatterscatterPlotDefinition
Bar chartexploreda/charts/barbarChartDefinition
Row chartexploreda/charts/rowrowChartDefinition
Line chartexploreda/charts/linelineChartDefinition
Box plotexploreda/charts/box-plotboxPlotDefinition
ECDFexploreda/charts/ecdfecdfDefinition
Heatmapexploreda/charts/heatmapheatmapDefinition
Calendar heatmapexploreda/charts/calendarcalendarDefinition
Hierarchyexploreda/charts/hierarchyhierarchyDefinition
Donutexploreda/charts/donutdonutDefinition
Funnelexploreda/charts/funnelfunnelDefinition
Retentionexploreda/charts/retentionretentionDefinition
Joint missingnessexploreda/charts/joint-missingnessjointMissingnessDefinition
Timelineexploreda/charts/timelinetimelineDefinition
Waterfallexploreda/charts/waterfallwaterfallDefinition
Sankey chartexploreda/charts/sankeysankeyDefinition
Parallel coordinatesexploreda/charts/parallel-coordinatesparallelCoordinatesDefinition
Scatter matrixexploreda/charts/scatter-matrixscatterMatrixDefinition
3D scatter plotexploreda/charts/three-d-scatterthreeDScatterDefinition
Mapexploreda/charts/mapmapDefinition
Compositionexploreda/charts/compositioncompositionDefinition
Data tableexploreda/charts/data-tabledataTableDefinition
Pivot tableexploreda/charts/pivot-tablepivotTableDefinition
Summary tableexploreda/charts/summary-tablesummaryTableDefinition
Metric cardexploreda/charts/metric-cardmetricCardDefinition
Color legendexploreda/charts/color-legendcolorLegendDefinition
Notesexploreda/charts/markdownmarkdownDefinition

Every chart type

Each chart below is a Chart drawn from the same 48 sample rows, with the config under it.

Loading charts…