-
Copy the htmlgraphics-html-bundler-template
- Either by clicking the "use this template button"
- or with the command
npx degit https://github.com/gapitio/htmlgraphics-html-bundler-template htmlgraphics-jspdf-example
-
Install the jspdf package with the command
npm install jspdf
-
Modify the
rollup.config.js
file as it needs theinlineDynamicImports
enabled.Insert
inlineDynamicImports: true
to the output section for onInit.ts insiderollup.config.js
on line 16. -
Add the following code to
src/onInit.ts
import "./style.css"; import { jsPDF } from "jspdf"; function getFirstMetricValue() { const valueField = data.series[0]?.fields[1]; if (valueField) { const length = valueField.values.length; return valueField.values.get(length - 1); } return "No data"; } function createPdf() { const doc = new jsPDF(); doc.text("Hello from HTMLGraphics!", 10, 10); doc.text(`First metric value: ${getFirstMetricValue()}`, 10, 20); doc.save("htmlgraphics.pdf"); } const button = htmlNode.querySelector("button"); if (button === null) { throw new Error("Button doesn't exist"); } button.addEventListener("click", createPdf);
-
Add the following code to
src/html.html
<div> <button>Download PDF</button> </div>
-
Run
npm run build
-
Copy the content from
dist/panel-options.json
to the HTMLGraphics panel inside Grafana.
generated from gapitio/htmlgraphics-html-bundler-template
-
Notifications
You must be signed in to change notification settings - Fork 1
ZuperZee/htmlgraphics-jspdf-example
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Example on how to use jsPDF inside HTMLGraphics
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published