SpectraViewer1D is the primary class for rendering 1D spectra in JSpectraViewer. It supports NMR, IR, UV/Vis, LC-MS, and EI-MS spectrum types. Initialize it with a container selector and an options object, then call draw() to render. It supports mirror plots, zoom/pan controls, a zoombox overview, and — for NMR — an integrated assignment table and 3D structure viewer.
Initialize with a CSS selector pointing to the container element and an options object. Call draw() after construction to render the spectrum.
import { SpectraViewer1D } from 'jsv2';
let viewer = new SpectraViewer1D("#graph-container", {
name: "nmr-viewer",
width: 1000,
height: 400,
chartType: "1D-NMR",
dataset: [{
dataArray: { x: [...], y: [...] },
normalize: true,
style: { strokeColor: "red", strokeWidth: 1 },
}],
axis: {
x: { enabled: true, reverse: true, label: { text: "Chemical Shift (ppm)" } },
y: { enabled: true, label: { text: "Intensity" } },
},
controls: { enabled: true },
});
viewer.draw();A unique identifier for this viewer instance.
string | default: nullWidth of the viewer canvas in pixels.
number | default: 800Height of the viewer canvas in pixels.
number | default: 400Inner padding around the plot area in pixels.
object | default:{ top: 50, bottom: 50, right: 50, left: 90 }Specifies the spectrum type. Controls axis defaults, bar vs. line rendering, and peak handling.
string | default: "1D-NMR" | ["1D-NMR", "1D-EIMS", "1D-LCMS", "1D-IR", "1D-UV"]Optional title rendered above the plot.
text: title stringfontSize: font size in pixelscolor: CSS color stringunderline: booleanGlobal tolerance for the Douglas-Peucker line simplification applied to all datasets.
Lower values preserve more detail; higher values improve render performance. Can also be set per dataset.number | default: 0.005An array of dataset objects to render. Each object describes one spectrum trace.
dataset: [{
dataArray: { x: [...], y: [...] },
isMirrorPlot: false,
normalize: true,
name: "My Spectrum",
id: "trace-1",
simplifyTolerance: 0.001,
style: { strokeColor: "red", strokeWidth: 1 },
}]The raw spectrum data. Both arrays must be the same length.
x: array of x values (ppm, m/z, wavenumber, wavelength)y: array of y intensity valuesWhen true, y values are normalized so the maximum equals 1.
boolean | default: falseWhen true, the dataset is rendered below the x-axis as a mirror spectrum for comparison.
boolean | default: falseDisplay name for this trace, shown in the legend.
string | default: nullUnique identifier for this trace. Used when programmatically referencing the dataset.
string | default: nullPer-dataset Douglas-Peucker tolerance. Overrides the top-level simplifyTolerance.
Visual style for this trace.
strokeColor: CSS color string for the linestrokeWidth: line width in pixels{ strokeColor: "steelblue", strokeWidth: 1 }Sets the minimum visible range for each axis. The viewer will not zoom out beyond these values.
x: [min, max]y: [min, max]Configuration for each axis. Both share the same shape.
enabled: boolean — show or hide this axisreverse: boolean — reverse the axis direction (e.g. NMR ppm, IR wavenumber)label.text: axis label stringlabel.fontSize: label font size in pixelsticks: approximate number of tick marks{ enabled: true, reverse: false, ticks: 10 }Configuration for horizontal and vertical grid lines. Both share the same shape.
enabled: booleanstrokeColor: CSS color stringstrokeWidth: line width in pixelsopacity: 0–1ticks: number of grid linesAn overview minimap rendered in a corner of the viewer showing the full spectrum with a highlighted window indicating the current zoom region.
Show or hide the zoombox.
boolean | default: falseCorner in which to render the zoombox.
string | default: "top-right" | ["top-right", "top-left", "bottom-right", "bottom-left"]Dimensions of the zoombox in pixels.
number | default: 200 / 100Show or hide the toolbar of interaction controls.
boolean | default: falseConfigure zoom behaviour.
horizontal: boolean — allow horizontal zoomvertical: boolean — allow vertical zoommax: maximum zoom multiplierConfigure pan behaviour.
horizontal: booleanvertical: booleanShow a reset button that returns the view to the initial zoom and pan.
boolean | default: falseEnable a download button.
formats: array of export formats — ["png", "svg", "pdf"]filename: default filename (without extension)NMR only. Renders a peak assignment table linked to the spectrum and optionally a 3D structure viewer. Requires NMR assignment data from the DataParser.
assignmentTable: {
enabled: true,
containerID: "#assignments",
clusterNavigationID: "#cluster-navigation-1",
data: [event.detail.assignmentData],
structure: {
containerID: "#structure",
use_jsmol: true,
show_atom_numbers: true,
show_hydrogen: true,
width: 400,
height: 400,
format: "nmrml",
},
}CSS selector for the element that will contain the assignment table.
string | requiredCSS selector for the cluster navigation element (multiplet navigator).
string | default: nullAssignment data array from event.detail.assignmentData provided by DataParser.
Configuration for the 3D molecular structure viewer panel.
containerID: CSS selector for the structure container elementuse_jsmol: boolean — use JSmol for 3D renderingshow_atom_numbers: boolean — overlay atom index labelsshow_hydrogen: boolean — show hydrogen atomswidth / height: dimensions in pixelsformat: source format, e.g. "nmrml"Renders the viewer into the container element. Must be called after construction.
| viewer.draw();Adds a second spectrum rendered below the x-axis for side-by-side comparison.
x: array of x valuesy: array of y valuesname: display name for the mirror tracecolor: CSS color stringviewer.add_mirror_spectrum({
x: event.detail.x,
y: event.detail.y,
name: "Mirror Spectrum",
color: "blue",
});Removes the mirror spectrum and restores the original y-axis range.
| viewer.remove_mirror_spectrum();