changeset 12:064a22ca49a7

Find way to render charts
author Lewin Bormann <lbo@spheniscida.de>
date Sun, 10 Jul 2022 15:42:40 -0700
parents 659c0f81f60c
children b538f811931e
files assets/testchart.html.hbs src/main.rs
diffstat 2 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/assets/testchart.html.hbs	Sun Jul 10 15:42:40 2022 -0700
@@ -0,0 +1,11 @@
+<html>
+    <head></head>
+    <body>
+        <script src="/static/chart.min.js" type="application/javascript"></script>
+        <canvas id="myChart" width="200" height="200"></canvas>
+        <script>
+            const ctx = document.getElementById('myChart').getContext('2d');
+            const myChart = new Chart(ctx, {{{ chartconfig }}});
+        </script>
+    </body>
+</html>
--- a/src/main.rs	Sun Jul 10 13:17:50 2022 -0700
+++ b/src/main.rs	Sun Jul 10 15:42:40 2022 -0700
@@ -342,6 +342,11 @@
     }
 }
 
+#[rocket::get("/testchart")]
+async fn route_testchart() -> Template {
+    Template::render("testchart", context![ chartconfig: create_linechart([1,2,3,4].iter(), [3,2,5,4].iter(), "Series".into()).to_string() ])
+}
+
 #[rocket::get("/static/<path>")]
 async fn route_static(
     cc: &rocket::State<CustomConfig>,
@@ -414,6 +419,8 @@
                 route_login_form,
                 route_login_post,
                 route_log,
+
+                route_testchart,
             ],
         )
 }