Snippets Animation

Bootstrap 5 Animated Line Chart with Tooltips

An animated line chart of yearly revenue with a soft area fill, gridlines and tooltips that appear on hover or keyboard focus.

Bootstrap 5 No jQuery Feb 2020 2.2K views

<section class="wdw-stage">
  <div class="container" style="max-width:860px">
    <div class="wdw-card p-4 p-md-5">
      <div class="d-flex flex-wrap justify-content-between align-items-start gap-3 mb-4">
        <div>
          <span class="wdw-eyebrow">Annual report</span>
          <h2 class="wdw-heading h3 mt-1 mb-1">Yearly revenue</h2>
          <p class="wdw-muted small mb-0">In millions, 2008 to 2015. Hover or focus a point for details.</p>
        </div>
        <div class="text-md-end">
          <div class="display-6 fw-bold text-body-emphasis lh-1" id="chartPeak">39.9</div>
          <div class="small wdw-muted mt-1">Peak revenue, millions</div>
        </div>
      </div>
      <div class="row g-3 mb-4">
        <div class="col-4"><div class="bg-body-tertiary rounded-4 p-3 h-100"><div class="small wdw-muted">Average</div><div class="fw-bold fs-5 text-body-emphasis" id="kpiAvg">-</div></div></div>
        <div class="col-4"><div class="bg-body-tertiary rounded-4 p-3 h-100"><div class="small wdw-muted">Best year</div><div class="fw-bold fs-5 text-body-emphasis" id="kpiBest">-</div></div></div>
        <div class="col-4"><div class="bg-body-tertiary rounded-4 p-3 h-100"><div class="small wdw-muted">Change</div><div class="fw-bold fs-5 text-body-emphasis" id="kpiChange">-</div></div></div>
      </div>
      <div class="btn-group mb-3 rounded-pill" role="group" aria-label="Year range" id="chartRange">
        <button type="button" class="btn btn-outline-primary rounded-start-pill active" data-range="0,7" aria-pressed="true">2008-2015</button>
        <button type="button" class="btn btn-outline-primary" data-range="0,3" aria-pressed="false">2008-2011</button>
        <button type="button" class="btn btn-outline-primary rounded-end-pill" data-range="4,7" aria-pressed="false">2012-2015</button>
      </div>
      <div class="wdw-chart position-relative">
        <svg id="lineChart" role="group" aria-label="Line chart of yearly revenue in millions, 2008 to 2015, peaking at 39.9 in 2009"></svg>
        <div class="wdw-tip" id="chartTip" aria-hidden="true" hidden></div>
      </div>
    </div>
  </div>
</section>

Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.