Display graphs
Use NMRGraphs for FID and FFT, and SVG functions for frequency sweeps, pulse calibration, T1 and T2. All previews below use simulated data without connecting to hardware.
Try the graphs in Storybook ↗. Change the language, width, signal conditions and FID/FFT colors without hardware. Storybook’s code examples use a preview-only React adapter; use the code on this page when building your own UI.
On this page
FID and FFT
Preparing the preview…
FID / time-domain signal
FFT / amplitude spectrum
The preview uses the same library as the example below. Replace the graph constructor in Your first Web UI with the following settings; keep the imports and result handler.
// Replace the NMRGraphs constructor in the first Web UI with this.
const graphs = new NMRGraphs({
fid: document.getElementById("fid"),
fft: document.getElementById("fft"),
displayEndMs: 10,
frequencyLimitHz: 10000,
locale: "en",
colors: { data1: "#176caa", data2: "#b34e25", fft: "#7c3aed" },
});For npm, import from nmrlink and nmrlink/graphs. The HTML examples assume the library source folder is available as ./nmrlink/.
displayEndMs: FID display end in ms (default 10).frequencyLimitHz: FFT display limit in ±Hz (default 10000); the axis uses kHz.colors: CSS colors fordata1,data2andfft. Omitted keys retain their defaults.
Display limits do not change the FFT analysis interval. The shaded FID region marks that interval. The vertical FID scale follows the analysis interval and clips larger early signals. Width follows the container; graph height stays at 280 px.
Pass an existing analysis to graphs.show(record, analysis) to reuse it. Optional peak and status elements display the peak and analysis description.
// When replacing the displayed result:
graphs.show(record, analysis);
// To clear the graphs:
graphs.clear();
// When removing the view:
graphs.dispose();Language and custom labels
Set locale to en for English or ja for Japanese (the default). Labels override only the supplied strings, keeping the other labels in the selected language. Titles also set the SVG accessible name. Empty strings hide the corresponding text. Label changes do not convert units or change analysis.
const graphs = new NMRGraphs({
fid: fidElement,
fft: fftElement,
locale: "en",
labels: {
fid: { title: "My FID", xLabel: "Time [ms]", yLabel: "Signal [a.u.]" },
fft: { xLabel: "Frequency offset [kHz]" },
},
});
const svg = createT1Plot(points, {
fit,
locale: "en",
labels: { title: "Inversion recovery", xLabel: "Delay τ [ms]" },
});NMRGraphs and createRecordPlots use nested labels.fid and labels.fft, each with title, xLabel and yLabel. The four curve functions use a flat labels object with the same three keys. NMRGraphs also accepts fid.empty and fft.empty for the text shown by clear().
For optional peak and status elements, use the following string templates. Omit them to use the built-in translation. Do not put HTML in labels; strings are displayed as text. Unknown keys, unsupported locales and non-string values are rejected.
// Pass this object as the labels option when creating NMRGraphs.
const labels = {
peak: {
empty: "No measurement",
none: "No signal",
outside: " (outside range)",
value: "Peak: {hz} Hz{outside}",
},
status: "FFT: {startMs}–{endMs} ms; {window}; baseline: {tailPoints} samples",
};peak.value supports {hz} and {outside}. status supports {tailPoints}, {displayEndMs}, {startMs}, {endMs}, {window} and {frequencyLimitKHz}. Unknown placeholder names are rejected. Set these options when creating the view; recreate it to change languages. PNG and SVG exports retain the displayed labels.
Response curves
Each example can be pasted into a separate HTML file. To combine them on one page, give each container a unique ID and update its selector. Blue dots are simulated samples; orange lines are fits. Replace the points with your analysis results. Fits are estimates, not a validation of the experiment.
Frequency response
Supply frequencyHz in Hz and a nonnegative amplitude. The horizontal axis is in kHz.
<div id="curve"></div>
<script type="module">
import { createFrequencyPlot } from "./nmrlink/graphs.js";
const points = Array.from({ length: 9 }, (_, i) => {
const frequencyHz = 398000 + i * 1000;
return { frequencyHz, amplitude: 1000 * Math.exp(-(((frequencyHz - 402000) / 1800) ** 2)) };
});
const options = {};
const element = document.querySelector("#curve");
function draw() {
const width = Math.max(160, Math.floor(element.clientWidth));
element.innerHTML = createFrequencyPlot(points, { ...options, width, locale: "en" });
}
const observer = new ResizeObserver(draw);
observer.observe(element);
draw();
// Call observer.disconnect() when removing this view.
</script>Pulse response
length is the RF cycle count; amplitude preserves the sign. The optional sine fit estimates 90° and 180° pulses.
<div id="curve"></div>
<script type="module">
import { createPulsePlot } from "./nmrlink/graphs.js";
import { fitPulseCalibration } from "./nmrlink/index.js";
const points = Array.from({ length: 16 }, (_, i) => {
const length = 5 + i * 5;
return { length, amplitude: 1000 * Math.sin(Math.PI * length / (2 * 21)) };
});
const options = { fit: fitPulseCalibration(points) };
const element = document.querySelector("#curve");
function draw() {
const width = Math.max(160, Math.floor(element.clientWidth));
element.innerHTML = createPulsePlot(points, { ...options, width, locale: "en" });
}
const observer = new ResizeObserver(draw);
observer.observe(element);
draw();
// Call observer.disconnect() when removing this view.
</script>T1 recovery
tau is in ms and signal is signed. The fit uses A − B exp(−τ/T1).
<div id="curve"></div>
<script type="module">
import { createT1Plot } from "./nmrlink/graphs.js";
import { fitT1 } from "./nmrlink/index.js";
const points = Array.from({ length: 20 }, (_, i) => {
const tau = 5 + i * 5;
return { tau, signal: 1000 * (1 - 2 * Math.exp(-tau / 20)) };
});
const options = { fit: fitT1(points, { fromMs: 5, toMs: 100 }) };
const element = document.querySelector("#curve");
function draw() {
const width = Math.max(160, Math.floor(element.clientWidth));
element.innerHTML = createT1Plot(points, { ...options, width, locale: "en" });
}
const observer = new ResizeObserver(draw);
observer.observe(element);
draw();
// Call observer.disconnect() when removing this view.
</script>T2 decay
Supply tau in ms and a nonnegative signal. The graph plots 2τ; fit limits are also expressed as 2τ in ms.
<div id="curve"></div>
<script type="module">
import { createT2Plot } from "./nmrlink/graphs.js";
import { fitT2 } from "./nmrlink/index.js";
const points = Array.from({ length: 16 }, (_, i) => {
const tau = 5 + i * 2;
return { tau, signal: 1000 * Math.exp(-2 * tau / 22) };
});
const options = { fit: fitT2(points, { fromMs: 10, toMs: 70 }) };
const element = document.querySelector("#curve");
function draw() {
const width = Math.max(160, Math.floor(element.clientWidth));
element.innerHTML = createT2Plot(points, { ...options, width, locale: "en" });
}
const observer = new ResizeObserver(draw);
observer.observe(element);
draw();
// Call observer.disconnect() when removing this view.
</script>Omit fit to show only the measured points. Pulse and T1 plots also support mode: "magnitude" using each point’s magnitude; T1 additionally supports "quadrature". T1 fits are shown only in signed mode. Color options above apply to NMRGraphs, not these four curve functions.
Pulse, T1 and T2 horizontal axes begin at zero without inventing a measurement at zero. ResizeObserver redraws these SVG curves to match their containers. Disconnect it when removing the view. NMRGraphs handles its own resize observer.