Replies: 2 comments 1 reply
-
Not sure what type of plotting you're doing. Would |
Beta Was this translation helpful? Give feedback.
-
Insanely cool stuff. I am actually trying some similar things. I am using wasm-bindgen to create a JS function that attaches a chart from Apex Charts to an HTML Element with minor success. It is loading on a refresh but it errors when navigating between pages. Maybe this can help/you can help figure out what I am doing incorrect?
// In the "view" of app.js
<Script src="https://cdn.jsdelivr.net/npm/apexcharts" />
// build_chart.js
export function buildChart(options) {
if (
document.getElementById("area-chart") && // This is true on initial load, but undefined when navigating between pages.
typeof ApexCharts !== "undefined" &&
options
) {
const chart = new ApexCharts(
document.getElementById("area-chart"),
options
);
chart.render();
}
}
use chart_options::*;
use leptos::*;
use wasm_bindgen::prelude::*;
pub mod chart_options;
#[wasm_bindgen(module = "/src/components/charts/apex_charts.js")]
extern "C" {
#[wasm_bindgen]
fn buildChart(options: JsValue);
}
#[component]
pub fn Chart(cx: Scope, chart_options: ReadSignal<ChartOptions>) -> impl IntoView {
create_effect(cx, move |_| {
match serde_wasm_bindgen::to_value(&chart_options.get()) {
Ok(config) => buildChart(config),
Err(_) => log!("Error while serializing chart options."),
}
});
view! {
cx,
<div id="area-chart"></div>
}
} With this I can get the chart to load on the initial refresh of the page... but when trying to navigate between different pages on the website, the chart then disappears and does not load. The problem seems to be that the JS function is looking for the element with ID "area-chart", but when navigating between pages, this element is added to the DOM after the JS Function is called resulting in no chart. |
Beta Was this translation helpful? Give feedback.
-
Looking to port an existing egui application that does real time plotting over to Leptos and wondering if anyone else has done the same, and what was their general approach.
Beta Was this translation helpful? Give feedback.
All reactions