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.
pnpm add exploredaimport { 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.
<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.
ChartConfigis typed per chart type, so your editor completes the settings of thetypeyou set.- A
colorFieldis enough to color a chart.Chartpicks 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.
- 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,
onConfigChangegives 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.
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
colorFieldis 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
--backgroundand--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
widthandheightto set the size in pixels. - Leave them out to fill the parent element. Give the parent a height, or the chart takes 300 px.
heightincludes the title line. Passtitle={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
ChartSettingspanel 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:
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
registerChartsonce, 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:
| Page | Entry | Up front |
|---|---|---|
| 34 charts covering all 27 types, with settings and a text config | exploreda/chart | 1,283 KB, the rest after first paint |
| A bar chart and a scatter plot | exploreda/chart-core | 1,425 KB |
| The first page, before types loaded on demand | exploreda/chart | 2,987 KB |
| Chart | Import from | Definition |
|---|---|---|
| Scatter plot | exploreda/charts/scatter | scatterPlotDefinition |
| Bar chart | exploreda/charts/bar | barChartDefinition |
| Row chart | exploreda/charts/row | rowChartDefinition |
| Line chart | exploreda/charts/line | lineChartDefinition |
| Box plot | exploreda/charts/box-plot | boxPlotDefinition |
| ECDF | exploreda/charts/ecdf | ecdfDefinition |
| Heatmap | exploreda/charts/heatmap | heatmapDefinition |
| Calendar heatmap | exploreda/charts/calendar | calendarDefinition |
| Hierarchy | exploreda/charts/hierarchy | hierarchyDefinition |
| Donut | exploreda/charts/donut | donutDefinition |
| Funnel | exploreda/charts/funnel | funnelDefinition |
| Retention | exploreda/charts/retention | retentionDefinition |
| Joint missingness | exploreda/charts/joint-missingness | jointMissingnessDefinition |
| Timeline | exploreda/charts/timeline | timelineDefinition |
| Waterfall | exploreda/charts/waterfall | waterfallDefinition |
| Sankey chart | exploreda/charts/sankey | sankeyDefinition |
| Parallel coordinates | exploreda/charts/parallel-coordinates | parallelCoordinatesDefinition |
| Scatter matrix | exploreda/charts/scatter-matrix | scatterMatrixDefinition |
| 3D scatter plot | exploreda/charts/three-d-scatter | threeDScatterDefinition |
| Map | exploreda/charts/map | mapDefinition |
| Composition | exploreda/charts/composition | compositionDefinition |
| Data table | exploreda/charts/data-table | dataTableDefinition |
| Pivot table | exploreda/charts/pivot-table | pivotTableDefinition |
| Summary table | exploreda/charts/summary-table | summaryTableDefinition |
| Metric card | exploreda/charts/metric-card | metricCardDefinition |
| Color legend | exploreda/charts/color-legend | colorLegendDefinition |
| Notes | exploreda/charts/markdown | markdownDefinition |
Every chart type
Each chart below is a Chart drawn from the same 48 sample rows, with the config under it.