Analyst price targets, rating gauges and EPS charts in 11 KB of plain SVG (zero dependencies)
General-purpose chart libraries are great at lines and bars. They are less great at the charts finance pages actually need: an analyst price-target fan, a Strong Sell to Strong Buy gauge, EPS beats and misses by quarter, a 52-week range bar. You end up pulling in a library weighing tens or hundreds of kilobytes and then writing the finance-specific parts yourself anyway.
So we wrote those charts once, in plain SVG, and open-sourced them: quotelinks/stock-charts. It's one file of about 31 KB minified (11 KB gzipped), with no dependencies and no build step.
Here it is running live (all data is fictional, ticker ACME):
Two lines of HTML
<div class="ql-chart" data-type="analyst-gauge" data-src="/data/msft-gauge.json"></div> <script src="https://cdn.jsdelivr.net/gh/quotelinks/stock-charts@1.0.1/dist/ql-charts.min.js" defer></script> Every element with class="ql-chart" and a data-type is rendered when the page loads. You can also self-host the file; it's a single script.
You bring the data
The library ships no market data and makes no network calls except to the URL you give it. That was a deliberate choice: you use whatever source you're licensed to display (your broker's API, a data vendor, your own database) and output a small JSON object. There are three ways to hand it over.
1. A URL (a static file or your own endpoint; it needs CORS if it's on another domain):
<div class="ql-chart" data-type="target-range" data-src="https://example.com/api/targets?symbol=MSFT"></div> 2. Inline JSON, which needs no extra request and works well for server-rendered pages:
<div class="ql-chart" data-type="analyst-ratings" data-theme="dark"> <script type="application/json"> {"symbol":"ACME","strongBuy":11,"buy":8,"hold":4,"sell":1,"strongSell":0} </script> </div> 3. The JavaScript API:
QLCharts.render(document.getElementById("eps"), "earnings-surprise", { symbol: "ACME", quarters: [ { period: "Q2 '26", estimate: 1.25, actual: 1.34 }, { period: "Q3 '26", estimate: 1.31, actual: 1.40 }, { period: "Q4 '26", date: "2027-01-27", estimate: 1.38 } // no "actual" = upcoming ] }, { theme: "auto" }); QLCharts.scan(); // render .ql-chart elements added after page load (SPAs) QLCharts.types; // the list of chart types The data formats are intentionally boring. Dates are YYYY-MM-DD, percentages are plain numbers (14.2 means 14.2%), and every type has a JSON Schema in the repo so you can validate your API output in CI.
// analyst-gauge — consensus: 1 = Strong Sell … 5 = Strong Buy { "symbol": "ACME", "price": 217.91, "target": 355.19, "consensus": 4.55, "analysts": 24 } // range-performance { "symbol": "ACME", "price": 217.91, "low52": 178.69, "high52": 307.25, "returns": { "1W": 2.4, "1M": -3.8, "YTD": 11.2, "1Y": 18.6 }, "benchmark": { "name": "S&P 500", "returns": { "1W": 0.9, "1M": 1.6, "YTD": 14.0, "1Y": 16.2 } } } The nine chart types
data-type | What it shows |
|---|---|
price-target | Last 12 months of prices fanning out to the highest, mean and lowest analyst targets, plus a summary table |
analyst-gauge | Consensus rating gauge with the 12-month target and upside |
target-range | High / mean / median / low targets vs. today's price |
analyst-ratings | Strong Buy … Strong Sell counts and percentages |
ratings-trend | Monthly recommendation counts as stacked columns |
price-chart | Area chart with 1M / 6M / YTD / 1Y / 5Y / Max buttons and a crosshair |
range-performance | 52-week range bar plus returns vs. a benchmark |
dividend-history | Dividends per share by year, yield, growth streak |
earnings-surprise | EPS actual vs. estimate by quarter, with the next report date |
Options are plain attributes: data-theme (light, dark, or auto, which follows the OS), data-frame="none" to drop the card border, and data-range for the price chart's default range.
A few engineering choices
Hand-built SVG, no chart engine. Each chart is a function that builds SVG nodes with createElementNS and a viewBox. There's no scene graph, animation system or plugin layer, which is most of where general chart libraries spend their bytes.
Shadow DOM. Each chart renders into its own shadow root, so your site's CSS can't break the charts and the charts' CSS can't leak into your page. That matters on WordPress and page builders, where a theme's global svg { width: 100% } or text { fill: ... } rule would otherwise wreck a chart.
Resizing without the ResizeObserver loop error. Charts are responsive down to 240 px wide and re-render when their container's width changes. Version 1.0.0 re-rendered inside the ResizeObserver callback, which triggered the famous "ResizeObserver loop completed with undelivered notifications" error. 1.0.1 defers the re-render to the next animation frame, ignores changes of 8 px or less, and detects a page scrollbar flipping the width back and forth so it doesn't re-render in a loop.
Never color alone. Red and green are hard to tell apart for a lot of people, so every up or down value also has a sign, an arrow or a label. Each SVG also gets role="img" and an aria-label that summarizes the data in words, for example "EPS actual vs estimate, beat 3 of 4 quarters".
Failure stays contained. If the JSON is missing or malformed, that one chart shows "Chart data unavailable" and the rest of the page carries on.
Credit link and license
Under each chart there's a small "Chart by Quotelinks" link. It's not required by the MIT license, and data-credit="off" removes it, but if the charts save you time, leaving it on is appreciated.
Want live data instead?
This library is deliberately data-agnostic. If you'd rather not run a data pipeline at all, we also have hosted stock widgets (quote cards, a scrolling ticker tape, market movers) that load prices themselves, and free JSON APIs for SEC fundamentals, insider trades and stock news you can query from a browser without a key.
- Repo and docs: github.com/quotelinks/stock-charts
- Live demo of all nine charts: quotelinks.github.io/stock-charts/examples
- Free stock quotes, charts and screeners: Quotelinks
Issues and pull requests are welcome, especially new chart types. Which finance chart do you find yourself building over and over?