Skip to content

Commit 9cbd71f

Browse files
committed
[simplest-plotly-streaming-chart] First cut
1 parent 27d077f commit 9cbd71f

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed
31.1 KB
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
^{:kindly/hide-code true
2+
:clay {:title "Simplest Plotly Streaming Chart"
3+
:quarto {:type :post
4+
:author [:harold]
5+
:date "2025-12-13"
6+
:description "Driving Plotly to Update a Chart with New Points."
7+
:image "simplest-plotly-streaming-chart.png"
8+
:category :data-visualization
9+
:tags [:chart :data :streaming :update]
10+
:keywords [:chart :data :streaming :update]}}}
11+
(ns data-visualization.simplest-ploty-streaming-chart
12+
(:require [scicloj.kindly.v4.kind :as kind]))
13+
14+
(kind/hiccup
15+
[:div#streaming-chart])
16+
17+
(kind/hiccup
18+
[:div
19+
[:script {:src "https://cdn.plot.ly/plotly-3.3.0.min.js"
20+
:type "application/javascript"}]
21+
[:script {:src "https://cdn.jsdelivr.net/npm/[email protected]/dist/scittle.js"
22+
:type "application/javascript"}]
23+
[:script {:src "simplestplotlystreamingchart.cljs"
24+
:type "application/x-scittle"}]])
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(ns data-visualization.simplestplotlystreamingchart)
2+
3+
(def id "streaming-chart")
4+
5+
(def v* (atom 0))
6+
7+
(js/Plotly.newPlot id (clj->js [{:y [@v*]}]))
8+
9+
(let [f (fn []
10+
(swap! v* + (- (* 2 (rand)) 1))
11+
(js/Plotly.extendTraces id (clj->js {:y [[@v*]]}) (clj->js [0])))
12+
i (js/setInterval f 300)]
13+
(js/setTimeout #(js/clearInterval i) 30000))

0 commit comments

Comments
 (0)