How to use timestamps when reading data from csv?

Yes, this is why I mentioned that.

I have used a modified version of How to transform a date input format into an output format? - #3 by TheJanzap and am suggesting you use something like this:

#import "@preview/lilaq:0.5.0" as lq

#let timestamp(t) = {
  let txt = str(t)  // Expected datetime format is "2018-10-21 14:53:54"
  let date = datetime(
    year: int(txt.slice(0, count: 4)),
    month: int(txt.slice(5, count: 2)),
    day: int(txt.slice(8, count: 2)),
    hour: int(txt.slice(11, count:2)),
    minute: int(txt.slice(14, count:2)),
    second: int(txt.slice(17, count:2)),
  )
  date
}

#let csv = ```csv
A,B,C,D
2019-10-01 15:00:00, 0, 2, "A"
2019-10-01 15:30:00, 1, 4, "B"
2019-10-01 16:00:00, 2, 6, "C"
```.text

#let data = lq.load-txt(
  csv,
  header: true,
  converters: (
    A: v => timestamp(v),
    D: v => str(v),
  ),
)

#lq.diagram(
    lq.plot(data.A, data.B),
)

Note that Data loading − Lilaq recommends:

JSON data is typed, i.e., there are strings, ints, floats, arrays, and objects (dictionaries) and the Typst function json automatically converts these types to Typst types (unlike with CSV).

2 Likes