Support for time#
Note
New in version 0.1.14. Datetime objects are converted to UNIX timestamps. Non-localized datetime objects are converted to UTC.
import easychart
import datetime
# fancy fibonacci one-liner
fib = lambda x: 1 if x < 2 else fib(x - 1) + fib(x - 2)
x = [datetime.time(x) for x in range(14)]
y = [fib(x + 1) for x in range(14)]
chart = easychart.new(datetime=True)
chart.plot(y, index=x, name="example")
chart
You can control the format of the X-axis labels and the tooltip header by adjusting their respective formats
import easychart
import datetime
# fancy fibonacci one-liner
fib = lambda x: 1 if x < 2 else fib(x - 1) + fib(x - 2)
x = [datetime.time(x) for x in range(14)]
y = [fib(x + 1) for x in range(14)]
chart = easychart.new(datetime=True)
chart.xAxis.labels.format = "{value:%H:%M}"
chart.tooltip.xDateFormat = "%H:%M"
chart.plot(y, index=x, name="another example")
chart
Formatting#
To format labels, the following formats are available.
%a
: Short weekday, like ‘Mon’
%A
: Long weekday, like ‘Monday’
%d
: Two digit day of the month, 01 to 31
%e
: Day of the month, 1 through 31
%w
: Day of the week, 0 through 6
%b
: Short month, like ‘Jan’
%B
: Long month, like ‘January’
%m
: Two digit month number, 01 through 12
%y
: Two digits year, like 09 for 2009
%Y
: Four digits year, like 2009
%H
: Two digits hours in 24h format, 00 through 23
%k
: Hours in 24h format, 0 through 23
%I
: Two digits hours in 12h format, 00 through 11
%l
: Hours in 12h format, 1 through 12
%M
: Two digits minutes, 00 through 59
%p
: Upper case AM or PM
%P
: Lower case AM or PM
%S
: Two digits seconds, 00 through 59
%L
: Milliseconds (naming from Ruby)
import pandas as pd
import easychart
chart = easychart.new("line", datetime=True)
chart.plot(
[1, 3, 5, 4, 3, 5, 2],
index=[pd.Timestamp(2022, 12, 8) + pd.Timedelta(days=i) for i in range(7)],
)
chart.xAxis.labels.format = "Midnight on {value:%d %b}"
chart