-
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.jsfile as it needs theinlineDynamicImportsenabled.Insert
inlineDynamicImports: trueto the output section for onInit.ts insiderollup.config.json line 16. -
Add the following code to
src/onInit.tsimport "./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.jsonto the HTMLGraphics panel inside Grafana.
forked from ZuperZee/htmlgraphics-jspdf-example
-
Notifications
You must be signed in to change notification settings - Fork 0
EmielRous/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
Languages
- TypeScript 41.7%
- JavaScript 39.0%
- HTML 10.0%
- CSS 9.3%
