Skip to main content

ECG Leads and How to Read an ECG Strip

What is an ECG?​

An electrocardiogram (ECG, or EKG) is a recording of the heart's electrical activity, picked up by electrodes on the skin. It plots voltage against time, and each heartbeat draws the same sequence of waves: a P wave, a QRS complex and a T wave. A standard 12-lead ECG shows that activity from twelve directions at once.

A simulated ECG rhythm strip of lead II on ECG paper, with a green trace sweeping across a grid of small and large squares and shaded calipers marking the PR interval, QRS duration and QT interval of the latest beat, in a dark navy theme

A simulated lead II rhythm strip on ECG paper, with the PR, QRS and QT intervals of the latest beat marked (sample data from a heart model, not a patient). Try the interactive version.

This guide explains how ECG traces are recorded, drawn and read. It is not clinical guidance: ECGs are interpreted by trained clinicians, alongside the patient.

Key takeaways
  • An ECG lead is a voltage between electrodes, not a wire: 10 electrodes give 12 leads, each viewing the heart from its own direction.
  • Each beat draws a P wave (the atria), a QRS complex (the ventricles) and a T wave (the ventricles recovering).
  • On standard paper (25 mm/s, 10 mm/mV) a small square is 0.04 s and 0.1 mV; a large square is 0.2 s and 0.5 mV.
  • Heart rate is 300 divided by the large squares between two R waves, or 1,500 divided by the small squares.
  • Read every strip in the same order: rate, rhythm, axis, intervals, then the shape of each wave.

What an ECG records​

Each heartbeat starts with an electrical impulse in the sinoatrial (SA) node, a small cluster of cells high in the right atrium. The impulse spreads across both atria, which contract. It is delayed briefly in the atrioventricular (AV) node, then runs down the bundle of His and its branches into the Purkinje fibres, which spread it through the ventricles from the inside out. The ventricles contract, then their cells recover (repolarise), ready for the next beat.

As the wave of activation moves through the heart muscle, the cells it has reached and the cells it hasn't yet reached sit at different voltages. Seen from outside, the whole heart behaves like a single electrical arrow, a dipole, that swings round and changes length through each beat. The body conducts that field to the skin, where it measures about one millivolt.

An electrode pair records how much of the arrow points along the line between them. When the activation moves towards the positive electrode, the trace goes up; when it moves away, the trace goes down; when it moves at right angles, the trace barely moves. So the same beat looks different in each lead, depending on where the lead's electrodes sit.

"ECG" and "EKG" mean the same thing. EKG comes from the German spelling, Elektrokardiogramm, and is common in the United States, partly so that it isn't misheard as EEG, the recording of brain activity.

ECG leads: what the 12 leads are​

A lead is one voltage measurement: the difference between a positive electrode and a negative reference. A standard 12-lead ECG uses ten electrodes, four on the limbs and six on the chest, and calculates twelve leads from them. The leads fall into three groups.

ECG electrode placement and lead directions. Left: the chest from the front with ten electrodes. RA and LA on the arms, LL on the left leg and RL on the right leg as the ground. V1 and V2 in the fourth intercostal space either side of the sternum, V4 in the fifth intercostal space on the midclavicular line, V3 halfway between V2 and V4, V5 on the anterior axillary line and V6 on the mid-axillary line level with V4. Top right: the limb leads as arrows in the frontal plane, I at 0 degrees, II at plus 60, aVF at plus 90, III at plus 120, aVL at minus 30 and aVR at minus 150. Bottom right: the chest leads V1 to V6 fanning round the horizontal plane from the front right to the left side. Colours group the leads as inferior, lateral, septal and anterior

Limb leads I, II and III​

The three standard limb leads each measure between two limb electrodes. Together they form Einthoven's triangle around the heart:

LeadPositive electrodeNegative electrodePoints towards
ILeft armRight arm0°, the patient's left
IILeft legRight arm+60°, down and to the left
IIILeft legLeft arm+120°, down and to the right

Because the three leads go round a closed loop of the same three electrodes, their voltages are linked at every instant: lead II equals lead I plus lead III (Einthoven's law). Lead II runs close to the usual direction of activation, so it usually shows the tallest, clearest P waves and QRS complexes, which is why monitors and rhythm strips default to it.

Augmented limb leads aVR, aVL and aVF​

The augmented leads use one limb electrode as the positive pole and the average of the other two as the reference. aVR looks from the right shoulder (−150°), aVL from the left shoulder (−30°) and aVF from the feet (+90°). "Augmented" refers to the way the reference is built, which makes the signal about 50% larger than measuring against all three electrodes. Activation normally moves away from the right shoulder, so most waves in aVR point downwards. Together with leads I, II and III, they divide the frontal plane every 30°: the hexaxial reference system.

Chest (precordial) leads V1 to V6​

Each chest lead compares one chest electrode with Wilson's central terminal, the average of the right arm, left arm and left leg electrodes. Because the electrodes sit close to the heart, they see the horizontal plane, from the front of the right ventricle (V1) round to the left side of the left ventricle (V6). Across V1 to V6 the R wave normally grows and the S wave shrinks; the lead where they are about equal, usually V3 or V4, is the transition zone.

ECG electrode placement​

ElectrodeWhere it goes
V1Fourth intercostal space, just right of the sternum
V2Fourth intercostal space, just left of the sternum
V3Halfway between V2 and V4
V4Fifth intercostal space, on the midclavicular line
V5Anterior axillary line, level with V4
V6Mid-axillary line, level with V4 and V5
RA, LARight and left arm, usually the wrists or upper arms
LLLeft leg, usually the ankle or lower leg
RLRight leg: the ground, not part of any lead

To find the fourth intercostal space, feel for the sternal angle (the ridge where the top of the breastbone joins its body) and move sideways onto the second rib. The gap just below it is the second intercostal space; count down two more gaps to the fourth. Placing V1 and V2 too high is one of the most common recording errors.

Lead groups: which leads look at which part of the heart​

Leads that face the same wall of the left ventricle are read together, because a change seen in two or more neighbouring (contiguous) leads is more meaningful than a change in one.

GroupLeadsFaces
InferiorII, III, aVFThe bottom of the heart
LateralI, aVL, V5, V6The left side
SeptalV1, V2The wall between the ventricles
AnteriorV3, V4The front
NoneaVRLooks into the cavity from the right shoulder

Other lead systems​

  • Monitoring leads. Bedside and transport monitors often use three electrodes (giving leads I, II and III) or five (adding one chest lead), with the limb electrodes moved onto the torso so the patient can move.
  • Torso-placed limb electrodes (the Mason-Likar position) are used for exercise tests. They change the waveform slightly, so the recording should be labelled.
  • Right-sided and posterior leads. V3R and V4R mirror V3 and V4 on the right of the chest; V7 to V9 continue round the back. They are added to look at the right ventricle or the back wall.

The ECG waveform: P, QRS, T and U waves​

Each normal heartbeat draws a P wave, a QRS complex and a T wave, sometimes followed by a small U wave, and the intervals between them are what an ECG reader measures.

Two heartbeats of lead II on ECG paper. The P wave, the Q, R and S waves and the T wave are labelled, with a small U wave after the T wave. Brackets mark the PR interval of 0.16 s (four small squares), the QRS duration of 0.09 s, the ST segment and the QT interval of 0.37 s. The RR interval between the two R waves is 0.80 s, four large squares or twenty small squares, so the heart rate is 300 divided by 4, or 1,500 divided by 20, which is 75 beats per minute. A 1 mV calibration pulse, 10 mm tall, is at the start. Below, a key shows a large square as 0.2 s by 0.5 mV and a small square as 0.04 s by 0.1 mV

  • P wave. Activation spreading through the atria. Small and rounded, normally upright in leads I and II.
  • PR segment. The flat line after the P wave, while the impulse is delayed in the AV node.
  • QRS complex. Activation of the ventricles. A Q wave is any first downward deflection, the R wave is the first upward one and an S wave is a downward one after the R. Not every lead shows all three, and the letters describe the shape: "rS" is a small r and a deep S.
  • ST segment. The line from the end of the QRS (the J point) to the start of the T wave, when the ventricles are fully activated. It is normally close to the baseline.
  • T wave. The ventricles recovering. Normally upright in most leads where the QRS is upright, and inverted in aVR.
  • U wave. A small wave sometimes seen after the T wave, best in V2 and V3. Its origin is still debated.

Atrial recovery happens during the QRS complex and is hidden by it, which is why there is no wave for it.

ECG intervals and normal values​

Intervals are measured from the start of one wave to the start or end of another, in the lead where the edges are clearest.

MeasureFrom → toTypical adult rangeIn small squares
Heart rate—60 to 100 beats per minute at rest—
PR intervalStart of P → start of QRS120 to 200 ms3 to 5
QRS durationStart → end of QRSUnder 120 ms, usually 80 to 110 msUnder 3
QT intervalStart of QRS → end of TDepends on heart rate: see QTc—
QTcQT corrected for rateProlonged at 450 ms or more (men), 460 ms or more (women)—
RR intervalOne R wave → the next0.6 to 1.0 s at 60 to 100 bpm15 to 25
Frontal axisDirection of the main QRS arrow−30° to +90°—

Some references use 50 bpm as the lower limit of a normal resting rate, and children have faster rates and shorter intervals. Measured values depend on the lead and the method, so a machine's printed numbers can differ from a careful manual measurement by a few milliseconds.

Correcting the QT interval for heart rate (QTc)​

The QT interval shortens as the heart speeds up, so a raw QT can't be compared between recordings at different rates. A corrected QT (QTc) estimates what it would be at 60 beats per minute, where the RR interval is 1 second. With QT and RR in seconds, the two best-known formulas are:

QTcBazett=QTRRQTcFridericia=QTRR3\mathrm{QTc}_{\mathrm{Bazett}} = \frac{QT}{\sqrt{RR}} \qquad \mathrm{QTc}_{\mathrm{Fridericia}} = \frac{QT}{\sqrt[3]{RR}}

Bazett's formula is the most widely printed, but it over-corrects at fast rates and under-corrects at slow ones. Take a QT of 313 ms at 125 beats per minute (RR = 0.48 s):

  • Bazett: 0.313/0.48=0.313/0.693≈0.4520.313 / \sqrt{0.48} = 0.313 / 0.693 \approx 0.452 s, or 452 ms, just over the 450 ms threshold for men.
  • Fridericia: 0.313/0.483=0.313/0.783≈0.4000.313 / \sqrt[3]{0.48} = 0.313 / 0.783 \approx 0.400 s, or 400 ms, well within the normal range.

So the same recording can look prolonged with one formula and normal with the other. The interactive ECG shows both side by side as you change the heart rate.

ECG paper: small squares, large squares and calibration​

ECG paper is printed with a grid of 1 mm squares, with every fifth line bolder. At the standard paper speed of 25 mm per second and gain of 10 mm per millivolt:

Width (time)Height (voltage)
Small square, 1 mm0.04 s (40 ms)0.1 mV
Large square, 5 mm0.2 s (200 ms)0.5 mV
5 large squares1 s—
10 small squares—1 mV

Every recording starts with a calibration pulse: a 1 mV step that should be 10 mm (two large squares) tall. Check it before measuring. Some recordings are made at 50 mm/s, which stretches every wave to twice the width, or at half or double gain (5 or 20 mm/mV) to fit very large or very small complexes; the settings are printed on the strip.

How to calculate heart rate from an ECG​

A minute at 25 mm/s is 1,500 mm of paper: 300 large squares or 1,500 small ones. Three methods follow from that.

  • 300 method: count the large squares between two consecutive R waves and divide 300 by that number. One large square is 300 bpm, then 150, 100, 75, 60 and 50 for two to six squares, a sequence worth memorising.
  • 1,500 method: count the small squares between two R waves and divide 1,500 by it. It is more precise.
  • 6-second method: count the QRS complexes in 6 seconds (30 large squares) and multiply by 10, or count them across a whole 10-second recording and multiply by 6. This is the only one of the three that works when the rhythm is irregular.

Worked examples:

StripCountCalculationHeart rate
Regular, R waves 4 large squares apart4 large300 ÷ 475 bpm
The same strip, counted in small squares20 small1,500 ÷ 2075 bpm
Regular, R waves 23 small squares apart23 small1,500 ÷ 23about 65 bpm
Irregular, 14 QRS complexes in a 10-second recording1414 × 6about 84 bpm

How to read an ECG strip, step by step​

A systematic order catches things a quick glance misses. The steps below follow the order taught in resuscitation and nursing courses for rhythm strips, with the extra checks used on a full 12-lead ECG.

  1. Check the recording. Confirm the patient details, the paper speed, the gain and the calibration pulse, and that the leads are labelled. Look for artefact: a fuzzy, jittery baseline from muscle tremor, or a wandering one from breathing or movement.
  2. Work out the heart rate with one of the methods above. Under 60 bpm is described as bradycardia and over 100 bpm as tachycardia.
  3. Decide whether the rhythm is regular. Mark two or three R waves on a piece of paper (or use calipers) and slide it along the strip. Are the RR intervals the same, regularly irregular (a repeating pattern) or irregularly irregular (no pattern at all)?
  4. Look at the atrial activity. Is there a P wave before every QRS complex, and a QRS after every P wave? Are the P waves upright in lead II and all the same shape? Is the PR interval constant?
  5. Measure the QRS width. A narrow QRS (under 120 ms) means the ventricles were activated through the normal conduction system; a broad one means they weren't, for example a bundle branch block or a beat starting in the ventricle.
  6. Estimate the axis (12-lead ECG only). See the table below.
  7. Measure the intervals. PR and QT, and the QTc from the RR interval before the beat.
  8. Look at the shape of each wave and segment. P wave size, Q waves, R wave progression across V1 to V6, the ST segments and the T waves, comparing contiguous leads.
  9. Compare with any earlier ECG of the same person. A change matters more than a single value.

Working out the axis from leads I and aVF​

The QRS axis is the average direction of ventricular activation in the frontal plane. A quick estimate uses whether the QRS is mainly positive or negative in two leads at right angles:

Lead ILead aVFAxisDescription
PositivePositive0° to +90°Normal
PositiveNegative0° to −90°Normal if lead II is positive (down to −30°); otherwise left axis deviation
NegativePositive+90° to +180°Right axis deviation
NegativeNegative−90° to ±180°Extreme (northwest) axis

For a finer estimate, find the limb lead where the QRS is most nearly equal up and down (isoelectric): the axis is at right angles to it.

Common heart rhythms on an ECG strip​

These are descriptions of how the strips look, not a guide to diagnosis.

RhythmRateRegularityP wavesQRS
Normal sinus rhythm60 to 100 bpmRegularUpright in II, one before every QRS, constant PRNarrow
Sinus tachycardiaOver 100 bpmRegularAs sinus rhythm; may merge into the preceding T wave at fast ratesNarrow
Sinus bradycardiaUnder 60 bpmRegularAs sinus rhythmNarrow
Atrial fibrillationVariesIrregularly irregularNone: a wavy, fibrillating baseline insteadUsually narrow
Premature ventricular complexes (PVCs)Underlying rhythmEarly beats break the patternNo P wave before the early beatEarly beat is broad and oddly shaped, with a T wave pointing the opposite way

A sinus tachycardia is often a normal response, to exercise, fever or anxiety for example. In atrial fibrillation the atria are activated chaotically, several hundred times a minute, and the AV node lets impulses through at random intervals, so no two RR intervals match. A PVC is usually followed by a pause: the next normal beat arrives two normal cycles after the one before the PVC (a compensatory pause). Many other rhythms exist, such as atrial flutter, heart blocks and ventricular tachycardia; they are beyond this guide.

How ECG monitors and recorders draw the trace​

A paper recorder pulls paper past a pen at a constant speed. A screen does the same job in one of two ways. A sweeping display redraws the trace from left to right over the old one, leaving a small gap ahead of the newest point; it is what most patient monitors use, because the waveform stays still while it is drawn. A scrolling display moves the whole trace left as new data arrives. Both are explained in the strip chart guide.

Behind the trace, the signal is sampled, digitised and filtered before it is drawn. Diagnostic recorders typically sample at 500 times a second or more.

ProblemWhat causes itFilter that removes it
Baseline wanderBreathing, movement, electrode contactHigh-pass filter
Mains hum at 50 or 60 HzNearby power cables and equipmentNotch filter
Fuzzy, jittery traceMuscle activity, shiveringLow-pass filter

Filters change the waveform as well as the noise. The AHA recommendations for diagnostic ECGs set the low-frequency cut-off at 0.05 Hz (or up to 0.67 Hz with linear-phase digital filters) and the high-frequency cut-off at 150 Hz for adults. Monitors often offer a narrower "monitoring" band, for example around 0.5 to 40 Hz, which gives a steadier trace but can distort the ST segment and reduce small, sharp features such as pacemaker spikes. Check which filter mode a strip was recorded in before reading its ST segments.

A printed 12-lead ECG is usually 10 seconds long and laid out as three rows of four columns. Each column shows 2.5 seconds of three leads (I, II and III; then aVR, aVL and aVF; then V1 to V3; then V4 to V6), recorded at the same moment, and a 10-second rhythm strip of one lead, usually lead II, runs along the bottom.

12-lead ECG vs rhythm strip vs Holter vs wearable ECG​

LeadsHow longUsed for
Resting 12-lead ECG1210 secondsA full picture of the heart from all directions: axis, conduction, the walls of the ventricle
Monitor rhythm strip1 to 3 at a time, from 3 or 5 electrodesContinuous, printed in 6 to 10 s stripsWatching rate and rhythm at the bedside or in an ambulance, with alarms
Holter or patch monitor1 to 3 (some record 12)24 hours to two weeks or moreCatching rhythm problems that come and go
Smartwatch or handheld ECGUsually 1 (similar to lead I)About 30 seconds, when the user starts itChecking the rhythm when symptoms happen

A single lead is enough to read rate and rhythm, but not axis, or changes confined to one wall of the heart.

Common ECG reading mistakes​

Many ECG misreadings come from how the trace was recorded, such as misplaced electrodes or the wrong gain, or from applying a rule of thumb where it doesn't fit.

  • Swapped arm electrodes. Reversing the left and right arm electrodes turns lead I upside down (negative P wave, QRS and T wave) and swaps aVR with aVL and lead II with lead III. An inverted lead I with an upright aVR is the clue.
  • Chest electrodes in the wrong place. V1 and V2 placed one or two spaces too high, or V4 to V6 placed by eye on a large chest, change the R wave progression and can mimic disease.
  • Ignoring the calibration pulse. At half gain every wave looks half its true height; at 50 mm/s every interval looks twice as long.
  • Using the 300 rule on an irregular rhythm. It gives a different answer for each pair of beats. Count the complexes over 6 or 10 seconds instead.
  • Reading artefact as an arrhythmia. Tremor, a loose electrode or tapping on a lead wire can look like fast, chaotic beats. Normal QRS complexes marching through the noise at a regular rate give it away.
  • Measuring the QT in the wrong lead or including the U wave. Use the lead with the longest clear QT, often II or V5, and end it where the T wave returns to the baseline.
  • Trusting Bazett's QTc at fast or slow rates. Cross-check with Fridericia's formula when the rate is outside about 60 to 100 bpm.
  • Relying on the machine's printed interpretation. Automated statements are a starting point. They miss things and over-call others, so the trace is always read by a person.

How to build an ECG chart in JavaScript, React or Angular​

The demo below sweeps twelve leads across the screen at 500 samples a second per lead, the rate of many diagnostic ECGs, and SciChart.js redraws every lead as new samples arrive. It simulates an ECG from a simple model of the heart's electrical activity: one rotating heart vector, seen by each lead from its own direction, so all twelve leads come from the same beats, and lead II always equals lead I plus lead III. It is sample data, not a patient recording.

Choose the Layout: a 4-second rhythm strip of one lead, about what a monitor screen shows, or the standard 12-lead layout with a lead II rhythm strip underneath. Pick a Lead to see the same beats from another direction: compare II with aVR, or V1 with V6. Rhythm switches between normal sinus rhythm, sinus tachycardia and bradycardia, atrial fibrillation and sinus rhythm with PVCs, and Heart rate sets the rate. Show intervals puts calipers on the latest normal beat, and the readouts give the rate, PR, QRS, QT and both QTc formulas. On most screen sizes the grid keeps the squares square, as on paper at 25 mm/s and 10 mm/mV. Hover for times and voltages. Press Pause to freeze the sweep, then scroll to zoom, drag to pan and double-click to reset.

Here is the code for this chart. The heart model, the rhythms and the measurements are plain JavaScript; SciChart.js draws the ECG paper grid, the sweeping traces and the calipers. The React and Angular versions show the core of it: one lead sweeping across ECG paper, fed by your own data.

// A sweeping ECG on ECG paper with SciChart.js: one lead or a 12-lead layout, with calipers on the latest beat
const {
SciChartSurface,
NumericAxis,
NumberRange,
EAutoRange,
FastLineRenderableSeries,
XyDataSeries,
BoxAnnotation,
TextAnnotation,
EHorizontalAnchorPoint,
EVerticalAnchorPoint,
SciChartJsNavyTheme,
CursorModifier,
MouseWheelZoomModifier,
ZoomPanModifier,
ZoomExtentsModifier
} = SciChart;
// or, for npm, import { SciChartSurface, ... } from "scichart"

const TRACE_COLOUR = "#3BD16F"; // monitors traditionally draw the ECG in green
const MV_PER_SECOND = MM_PER_SECOND / MM_PER_MV; // 2.5 mV of height looks as tall as 1 s is wide
const ROW_BASELINES = [4.3, 1.3, -1.7, -4.6]; // mV: three rows of four leads, then the rhythm strip

const { sciChartSurface, wasmContext } = await SciChartSurface.create(ui.chart, {
theme: new SciChartJsNavyTheme()
});

// ECG paper: a small square is 1 mm (0.04 s by 0.1 mV) and a large square 5 mm (0.2 s by 0.5 mV)
const xAxis = new NumericAxis(wasmContext, {
axisTitle: "Time in sweep (s)",
autoRange: EAutoRange.Never,
autoTicks: false,
majorDelta: 0.2,
minorDelta: 0.04,
drawMajorBands: false,
majorGridLineStyle: { color: "#E0607E80", strokeThickness: 1 },
minorGridLineStyle: { color: "#E0607E30", strokeThickness: 1 },
cursorLabelPrecision: 2
});
xAxis.labelProvider.formatLabel = (value) =>
Math.abs(value - Math.round(value)) < 1e-6 ? `${Math.round(value)}` : "";
const yAxis = new NumericAxis(wasmContext, {
axisTitle: "mV",
autoRange: EAutoRange.Never,
autoTicks: false,
majorDelta: 0.5,
minorDelta: 0.1,
drawMajorBands: false,
majorGridLineStyle: { color: "#E0607E80", strokeThickness: 1 },
minorGridLineStyle: { color: "#E0607E30", strokeThickness: 1 },
labelPrecision: 0,
cursorLabelPrecision: 2
});
yAxis.labelProvider.formatLabel = (value) =>
Math.abs(value - Math.round(value)) < 1e-6 ? `${Math.round(value)}` : "";
sciChartSurface.xAxes.add(xAxis);
sciChartSurface.yAxes.add(yAxis);

// Calipers on the latest complete beat: shaded spans for the PR interval, the QRS and the QT interval
const caliper = (fill, stroke) =>
new BoxAnnotation({ fill, stroke, strokeThickness: 1, x1: 0, x2: 0, y1: 0, y2: 0, isHidden: true });
const label = (textColor, horizontalAnchorPoint, verticalAnchorPoint) =>
new TextAnnotation({
text: "",
textColor,
fontSize: 13,
x1: 0,
y1: 0,
isHidden: true,
horizontalAnchorPoint,
verticalAnchorPoint
});
const calipers = {
// The PR label sits to the left of the P wave, the QRS label above the R wave and the QT label underneath
qt: {
box: caliper("#F6E05E18", "#F6E05E99"),
text: label("#F6E05E", EHorizontalAnchorPoint.Left, EVerticalAnchorPoint.Top)
},
pr: {
box: caliper("#50C7E030", "#50C7E0CC"),
text: label("#50C7E0", EHorizontalAnchorPoint.Right, EVerticalAnchorPoint.Bottom)
},
qrs: {
box: caliper("#FF8A3D40", "#FF8A3DCC"),
text: label("#FF8A3D", EHorizontalAnchorPoint.Left, EVerticalAnchorPoint.Bottom)
}
};
Object.values(calipers).forEach(({ box, text }) => sciChartSurface.annotations.add(box, text));
// Lead names for the 12-lead layout, at the start of each column
const leadLabels = [];
const leadLabel = (lead, x, baseline) =>
new TextAnnotation({
text: lead,
textColor: "#FFFFFF",
fontSize: 14,
x1: x + 0.08,
y1: baseline + 1.2,
verticalAnchorPoint: EVerticalAnchorPoint.Bottom
});

// Hover for the time and voltage; pause, then scroll to zoom, drag to pan and double-click to reset
const cursor = new CursorModifier({ showTooltip: true, tooltipContainerBackground: "#14233CDD" });
sciChartSurface.chartModifiers.add(
cursor,
new MouseWheelZoomModifier(),
new ZoomPanModifier(),
new ZoomExtentsModifier({
onZoomExtents: () => {
setView(true);
return false; // back to the calibrated ECG paper view, not to the data
}
})
);

// --- Traces: a fixed time grid per trace. The sweep writes into it from left to right, then wraps around. ---
let layout = "single";
let windowSeconds = 4;
let traces = []; // { leadAt(i), offset(i), ys, dataSeries }
let xs = [];
function buildTraces() {
traces.forEach((trace) => sciChartSurface.renderableSeries.remove(trace.line, true));
leadLabels.forEach((annotation) => sciChartSurface.annotations.remove(annotation, true));
leadLabels.length = 0;
windowSeconds = layout === "single" ? 4 : 10; // a 4-second strip, as on a monitor screen, or a 10-second 12-lead
const count = windowSeconds * SAMPLE_RATE;
xs = Array.from({ length: count }, (_, i) => i / SAMPLE_RATE);
const columnLength = count / 4;
const rows =
layout === "single"
? [{ name: `Lead ${ui.lead.value}`, leadAt: () => ui.lead.value, baseline: 0, isColumns: false }]
: [
...TWELVE_LEAD_ROWS.map((row, r) => ({
name: row.join(", "),
leadAt: (i) => row[Math.floor(i / columnLength)],
baseline: ROW_BASELINES[r],
isColumns: true
})),
{
name: "Rhythm strip, lead II",
leadAt: () => "II",
baseline: ROW_BASELINES[3],
isColumns: false
}
];
traces = rows.map((row) => {
const dataSeries = new XyDataSeries(wasmContext, {
dataSeriesName: row.name,
isSorted: true,
containsNaN: true
});
const line = new FastLineRenderableSeries(wasmContext, {
dataSeries,
stroke: TRACE_COLOUR,
strokeThickness: 1.5
});
sciChartSurface.renderableSeries.add(line);
return { ...row, ys: new Float64Array(count).fill(NaN), dataSeries, line };
});
if (layout === "twelve") {
TWELVE_LEAD_ROWS.forEach((row, r) =>
row.forEach((lead, c) => {
leadLabels.push(leadLabel(lead, c * (windowSeconds / 4), ROW_BASELINES[r]));
})
);
leadLabels.push(leadLabel("II", 0, ROW_BASELINES[3]));
leadLabels.forEach((annotation) => sciChartSurface.annotations.add(annotation));
}
cursor.showTooltip = layout === "single"; // in the 12-lead layout, rows are offset, so only times are shown
cursor.showYLine = layout === "single";
yAxis.drawLabels = layout === "single";
yAxis.axisTitle = layout === "single" ? "mV" : "";
setView(true);
}

// Keeps the squares square at 25 mm/s and 10 mm/mV, whatever the size of the chart
let lastAspect = 0;
function setView(force) {
const rect = sciChartSurface.seriesViewRect;
const hasSize = Boolean(rect) && rect.width > 0 && rect.height > 0;
const aspect = hasSize ? rect.height / rect.width : 0.45; // before the first layout, assume a typical shape
if (!force && Math.abs(aspect - lastAspect) < 0.005) return;
lastAspect = aspect;
// On very wide or very tall screens, stretch the squares a little to keep the waves in view
const [minimum, maximum] = layout === "single" ? [3.5, 5.5] : [12.4, 15];
const span = Math.min(maximum, Math.max(minimum, windowSeconds * MV_PER_SECOND * aspect));
const centre = layout === "single" ? 0.4 : 0;
xAxis.visibleRange = new NumberRange(0, windowSeconds);
yAxis.visibleRange = new NumberRange(centre - span / 2, centre + span / 2);
// Hide the small squares when they would be less than 4 pixels wide
const pixelsPerSmallSquare = hasSize ? (rect.width / windowSeconds) * 0.04 : 4;
xAxis.drawMinorGridLines = pixelsPerSmallSquare >= 4;
yAxis.drawMinorGridLines = pixelsPerSmallSquare >= 4;
}

// --- The live sweep ---
const generator = createRhythmGenerator();
let sample = 0; // samples drawn so far
let running = true;
const settings = { rhythm: "normal", heartRate: 72, showIntervals: true };
const GAP = Math.round(0.2 * SAMPLE_RATE); // a 0.2 s gap ahead of the sweep, as on a monitor

// Writes sample number s into every trace, at its place in the sweep
function writeSample(s) {
const length = xs.length;
const t = s / SAMPLE_RATE;
const i = s % length;
const h = heartVector(generator.beats, t, settings.rhythm === "af");
const wander = 0.04 * Math.sin(2 * Math.PI * 0.21 * t); // slow baseline wander, e.g. from breathing
for (const trace of traces) {
// Break the line where one lead ends and the next begins, as on a printed 12-lead
const isColumnStart = trace.isColumns && i % (length / 4) === 0;
trace.ys[i] = isColumnStart
? NaN
: trace.baseline + leadVoltage(trace.leadAt(i), h) + wander + 0.012 * gaussian();
}
}

// Clears the gap ahead of the write position and sends the traces to the chart
function refresh() {
const length = xs.length;
const writeAt = sample % length;
for (const trace of traces) {
for (let g = 0; g < GAP; g++) trace.ys[(writeAt + g) % length] = NaN;
trace.dataSeries.clear();
trace.dataSeries.appendRange(xs, trace.ys);
}
}

function addSamples(count) {
generator.extend((sample + count) / SAMPLE_RATE + 1, settings.rhythm, settings.heartRate);
for (let n = 0; n < count; n++) writeSample(sample++);
refresh();
}

// Redraws the sweep on screen from the beats already made, after a change of lead or layout
function redrawSweep() {
const start = Math.max(0, sample - xs.length + GAP);
for (let s = start; s < sample; s++) writeSample(s);
refresh();
}

// --- Readouts ---
const readoutNames = ["Rhythm", "Heart rate", "PR", "QRS", "QT", "QTc (Bazett)", "QTc (Fridericia)", "Paper"];
const readouts = readoutNames.map((name) => {
const tile = document.createElement("div");
tile.style.cssText = "padding:2px 10px; border-radius:6px; background:#14233C; min-width:76px;";
tile.innerHTML = `<div style="font-size:11px; color:#c8d3e8">${name}</div><div style="font-size:15px; font-weight:600">–</div>`;
ui.readoutRow.append(tile);
return tile.lastElementChild;
});
const ms = (seconds) => (isFinite(seconds) ? `${Math.round(seconds * 1000)} ms` : "–");

function rhythmName(rate) {
if (settings.rhythm === "af") return "Atrial fibrillation";
if (settings.rhythm === "pvc") return "Sinus rhythm with PVCs";
return rate > 100 ? "Sinus tachycardia" : rate < 60 ? "Sinus bradycardia" : "Normal sinus rhythm";
}

// Measures the latest complete beat, places the calipers on it and updates the readouts
function measure() {
const now = sample / SAMPLE_RATE;
const done = generator.beats.filter((beat) => beat.tEnd + 0.05 < now && beat.qrsOn > now - 8);
// Heart rate from the QRS complexes of the last 6 seconds, as a monitor counts them
const recent = done.filter((beat) => beat.qrsOn > now - 6);
const rate =
recent.length > 1 ? (60 * (recent.length - 1)) / (recent[recent.length - 1].qrsOn - recent[0].qrsOn) : NaN;
// The calipers go on the latest normally conducted beat that sits within one sweep
let index = -1;
for (let k = done.length - 1; k > 0 && index < 0; k--) {
const beat = done[k];
const start = isFinite(beat.pOn) ? beat.pOn : beat.qrsOn;
const sameSweep = Math.floor(start / windowSeconds) === Math.floor((beat.tEnd + 0.1) / windowSeconds);
if (beat.kind === "normal" && sameSweep) index = k;
}
const beat = index > 0 ? done[index] : null;
const rr = beat ? beat.qrsOn - done[index - 1].qrsOn : NaN; // the RR interval before this beat
const qt = beat ? beat.tEnd - beat.qrsOn : NaN;
const values = [
rhythmName(settings.heartRate),
isFinite(rate) ? `${Math.round(rate)} bpm` : "–",
beat && isFinite(beat.pOn) ? ms(beat.qrsOn - beat.pOn) : beat ? "no P waves" : "–",
beat ? ms(beat.qrsOff - beat.qrsOn) : "–",
ms(qt),
ms(qt / Math.sqrt(rr)),
ms(qt / Math.cbrt(rr)),
`${MM_PER_SECOND} mm/s, ${MM_PER_MV} mm/mV`
];
values.forEach((text, k) => (readouts[k].textContent = text));

const show = Boolean(beat) && settings.showIntervals;
Object.values(calipers).forEach(({ box, text }) => {
box.isHidden = !show;
text.isHidden = !show;
});
if (!show) return;
const toX = (t) => t - Math.floor(beat.qrsOn / windowSeconds) * windowSeconds;
const baseline = traces[traces.length - 1].baseline; // the single trace, or the 12-lead rhythm strip
// Each caliper is a shaded span from one wave's start to another's end, with its label at (labelX, labelY)
const place = ({ box, text }, from, to, bottom, top, labelX, labelY, caption) => {
box.isHidden = !isFinite(from);
text.isHidden = !isFinite(from);
if (!isFinite(from)) return;
box.x1 = toX(from);
box.x2 = toX(to);
box.y1 = baseline + bottom;
box.y2 = baseline + top;
text.x1 = toX(labelX);
text.y1 = baseline + labelY;
text.text = caption;
};
place(calipers.pr, beat.pOn, beat.qrsOn, -0.3, 0.5, beat.pOn, 0.5, `PR ${ms(beat.qrsOn - beat.pOn)}`);
place(
calipers.qrs,
beat.qrsOn,
beat.qrsOff,
-0.3,
1.75,
beat.qrsOn,
1.75,
`QRS ${ms(beat.qrsOff - beat.qrsOn)}`
);
place(calipers.qt, beat.qrsOn, beat.tEnd, -0.55, -0.85, beat.qrsOn, -0.85, `QT ${ms(qt)}`);
}

// Add the samples that have arrived since the last update, about 30 times a second
let lastTime = performance.now();
let carry = 0;
const timer = setInterval(() => {
const time = performance.now();
const due = Math.min(((time - lastTime) * SAMPLE_RATE) / 1000, SAMPLE_RATE / 4) + carry;
lastTime = time;
if (!running) return;
const count = Math.floor(due);
carry = due - count;
if (count > 0) {
addSamples(count);
measure();
setView(false);
}
}, 33);
sciChartSurface.addDeletable({ delete: () => clearInterval(timer) });

// --- Controls ---
const PRESET_RATES = { normal: 72, tachycardia: 125, bradycardia: 48, af: 100, pvc: 72 };
const readControls = () => {
settings.heartRate = Number(ui.rate.value);
settings.showIntervals = ui.intervals.checked;
ui.rateOut.textContent = `${settings.heartRate} bpm`;
ui.lead.disabled = layout === "twelve";
};
const setRunning = (value) => {
running = value;
ui.run.textContent = running ? "Pause" : "Resume";
if (running) setView(true);
};
ui.rhythm.addEventListener("change", () => {
settings.rhythm = ui.rhythm.value === "af" || ui.rhythm.value === "pvc" ? ui.rhythm.value : "sinus";
ui.rate.value = String(PRESET_RATES[ui.rhythm.value]);
readControls();
});
ui.rate.addEventListener("input", () => {
readControls();
// The three sinus presets are the same rhythm at different rates, so follow the rate
if (settings.rhythm === "sinus") {
const rate = settings.heartRate;
ui.rhythm.value = rate > 100 ? "tachycardia" : rate < 60 ? "bradycardia" : "normal";
}
});
ui.intervals.addEventListener("change", () => {
readControls();
measure();
});
ui.lead.addEventListener("change", () => {
traces[0].dataSeries.dataSeriesName = `Lead ${ui.lead.value}`;
redrawSweep(); // show the whole strip in the new lead at once
});
ui.layout.addEventListener("change", () => {
layout = ui.layout.value;
readControls();
buildTraces();
redrawSweep();
measure();
});
ui.run.addEventListener("click", () => setRunning(!running));
// Zooming or panning pauses the sweep, so the live update doesn't undo it
const pauseForZoom = () => running && setRunning(false);
ui.chart.addEventListener("wheel", pauseForZoom);
ui.chart.addEventListener("pointerdown", pauseForZoom);

settings.rhythm = "sinus";
readControls();
buildTraces();
// Start with one full sweep already drawn
addSamples(xs.length - GAP);
measure();
sciChartSurface.rendered.subscribe(() => running && setView(false));

Key points:

  • Each trace is a FastLineRenderableSeries over an XyDataSeries of millivolts against time. NaN values break the line, which the 12-lead layout uses between columns and the sweep uses for the gap ahead of the newest point.
  • The ECG paper is the axes' own gridlines: autoTicks: false with majorDelta and minorDelta set to 0.2 s and 0.04 s on the x-axis and 0.5 mV and 0.1 mV on the y-axis. The demo sets the y-axis range from the plot area's shape so that 1 s is as wide as 2.5 mV is tall, as on paper.
  • The calipers are BoxAnnotations with TextAnnotation labels, moved to the latest complete beat on each update.
  • For a monitor fed by a device, fifoCapacity with fifoSweeping gives the sweeping display with no buffer code of your own, as in the React and Angular versions.

See it in the demo app: JavaScript ECG vital signs chart · React ECG vital signs chart · Angular ECG vital signs chart, and for several live signals at once, JavaScript real-time chart performance.

Go deeper: SciChart.js line chart documentation, real-time updates and FIFO sweeping and the box annotation documentation. For how SciChart is used in patient monitoring and medical research software, see SciChart for medical charts and dashboards and SciChart for telehealth.

Frequently asked questions​

What are the 12 leads of an ECG?​

The 12 leads are six limb leads and six chest leads. The limb leads, I, II, III, aVR, aVL and aVF, look at the heart in the frontal plane, from above, below and the sides. The chest (precordial) leads, V1 to V6, look at it in the horizontal plane, from the front of the chest round to the left side. Each lead is a voltage measured between electrodes, so it shows the same heartbeat from its own direction.

Why does a 12-lead ECG use only 10 electrodes?​

A lead is a measurement, not a wire. The six limb leads are all calculated from three limb electrodes (right arm, left arm and left leg), and the six chest leads each compare one chest electrode with the average of those three. The tenth electrode, on the right leg, is a ground that reduces interference and isn't part of any lead.

How do you read an ECG strip?​

Use the same order every time. Check the paper speed, gain and lead labels; work out the heart rate; decide whether the rhythm is regular and whether a P wave comes before every QRS complex; estimate the axis from leads I and aVF; measure the PR interval, QRS duration and QT interval; then look at the shape of each wave and segment. A trained clinician interprets the result alongside the patient.

What do the small and large squares on ECG paper mean?​

At the standard settings of 25 mm per second and 10 mm per millivolt, a small 1 mm square is 0.04 seconds wide and 0.1 mV tall, and a large 5 mm square is 0.2 seconds wide and 0.5 mV tall. Five large squares make one second, so a minute is 300 large squares or 1,500 small ones. That is where the 300 and 1,500 rules for heart rate come from.

What are the normal PR, QRS and QT intervals?​

In adults the PR interval is usually 120 to 200 ms (three to five small squares) and the QRS duration under 120 ms (three small squares). The QT interval depends on heart rate, so it is corrected to QTc; AHA/ACCF/HRS recommendations treat a QTc of 450 ms or more in men and 460 ms or more in women as prolonged. Normal ranges vary with age and between references.

How do I draw an ECG chart in JavaScript?​

Plot the samples in millivolts against time with a line series, on fixed axes with major gridlines every 0.2 s and 0.5 mV and minor gridlines every 0.04 s and 0.1 mV, so the grid matches ECG paper. For a live monitor, append new samples to a FIFO data series in sweep mode, which redraws from left to right with a gap ahead of the newest point. SciChart.js does this with FastLineRenderableSeries and XyDataSeries with fifoSweeping.

Sources​