File: chart-line.lua

package info (click to toggle)
lxi-tools 2.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,956 kB
  • sloc: ansic: 6,110; xml: 146; sh: 24; python: 12; makefile: 5
file content (34 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-------------------------------------
--  lxi-tools                      --
--    https://lxi-tools.github.io  --
-------------------------------------

-- Line chart test - plotting a sine wave function

-- Init
clock0 = lxi_clock_new()
chart0 = lxi_chart_new("line",                                -- chart type
                      "Sine wave plot, f(t) = 5 + 2sin(10t)", -- title
                      "Time [ s ]",                           -- x-axis label
                      "Value [  ]",                           -- y-axis label
                      10, 10, 800)                            -- x max, y max, window width

-- Sample and plot sine wave at 100 Hz for 10 seconds
clock = 0
while (clock < 10)
do
   clock = lxi_clock_read(clock0)
   value = 5 + 2*math.sin(10*clock)
   lxi_chart_plot(chart0, clock, value)
   lxi_msleep(10)
end

-- Save chart data
lxi_chart_save_csv(chart0, "chart0.csv")
lxi_chart_save_png(chart0, "chart0.png")

-- Cleanup
lxi_clock_free(clock0)
--lxi_chart_close(chart0)

print("Done")