(ns org.rssys.xchart (:gen-class) (:require [clojure.math :as math] [com.brunobonacci.mulog :as mulog] [com.hypirion.clj-xchart :as c]) (:import (org.knowm.xchart XYChart))) (def chart ^XYChart (c/xy-chart {"Sin" [(range 0 63) (range 0 63)] "Cos" [(range 0 63) (range 0 63)]})) ;; 63 is the number of dots to plot (def frame (c/view chart)) (dotimes [n 100] (let [start-x (* 2.0 math/PI (+ (* 0.01 n) n)) x-data (range start-x (* 2.0 math/PI (+ (* 0.01 n) (inc n))) 0.1) sin-y-data (map math/sin x-data) cos-y-data (map math/cos x-data)] (Thread/sleep 28) (.updateXYSeries chart "Sin" x-data sin-y-data nil) (.updateXYSeries chart "Cos" x-data cos-y-data nil) (.revalidate (.getContentPane frame)) (.repaint (.getContentPane frame)))) ;;;;;;;;;;;;;;;;;;;;;; (def chart ^XYChart (c/xy-chart {"Expected rate" [(range 10 20) (range 20 30)]})) (def frame (c/view chart)) (.updateXYSeries chart "Expected rate" (repeatedly 10 #(rand-int 10)) (range 30 40) nil) (.revalidate (:contentPane (bean frame))) (.repaint (:contentPane (bean frame))) (.revalidate (.getContentPane frame)) ;; the same (.repaint (.getContentPane frame)) (dotimes [n 100] (Thread/sleep 100) (.updateXYSeries chart "Expected rate" (repeatedly 10 #(rand-int 30)) (range 30 40) nil) (.revalidate (:contentPane (bean frame))) (.repaint (:contentPane (bean frame)))) (dotimes [n 100] (Thread/sleep 100) (.updateXYSeries chart "Expected rate" (repeatedly 10 #(rand-int 30)) (repeatedly 10 #(rand-int 90)) nil) (.revalidate (.getContentPane frame)) (.repaint (.getContentPane frame)))