- Stable
3.1.5- Canary
4.0.0-alpha.7
- Guide
Guide
- Get Started
- Command Line Usage
- Add a Configuration File
- Copy Files to Output
- Add CSS, JS, Fonts
- Importing Content
- Configure Templates with Data
- Using Data in Templates
- Template Languages
- Template Features
- Environment Variables
- Internationalization (i18n)
- Watch Files and Dev Servers
- Common Pitfalls
- Advanced
- Plugins
- Services
Sparklines
Deprecated
The runtime service for Sparkline SVG is deprecated and will likely go away at some future date. Please switch to use a build-time SVG package directly (e.g.
sparkline-svg). Sample code shown below. If you’re using Web Awesome, they have a Sparkline too!// don’t forget to `npm install sparkline-svg`
import Sparkline from "sparkline-svg";
function sparklineDataUri(values = []) {
let line = new Sparkline.default(values);
line.setViewBoxWidth(120);
line.setViewBoxHeight(30);
line.setStrokeWidth(1);
line.setStroke("#000000");
return line.dataUri;
};
// Example JavaScript Usage:
// `<img src="${sparklineDataUri([1, 2, 3])}" alt="Sparkline …">`
Deprecated: Feed this runtime service a comma separated list of numeric values and it will return an SVG sparkline image.
Usage
Image URLs have the format:
https://v1.sparkline.11ty.dev/:dimensions/:values/
https://v1.sparkline.11ty.dev/:dimensions/:values/:color/
dimensionsmust be two integers separated by anx.[height]x[width], e.g.120x30valuesmust be a comma separated list of numbers.coloris an SVG friendly color (URI encoded).
Samples
Using color #123456:
<img
src="https://v1.sparkline.11ty.dev/120x30/41,25,9,12,10,6,12,14,19,17,23,30,36,21,40/%23123456/"
width="120"
height="30"
alt="Sparkline representing frequency of posts written from 2007 to 2021"
loading="lazy"
decoding="async"
/>