@@ -1,26 +0,0 @@
|
||||
# Create a chart
|
||||
chart = lv.chart(lv.screen_active())
|
||||
chart.set_size(200, 150)
|
||||
chart.center()
|
||||
chart.set_type(lv.chart.TYPE.LINE) # Show lines and points too
|
||||
|
||||
# Add two data series
|
||||
ser1 = chart.add_series(lv.palette_main(lv.PALETTE.RED), lv.chart.AXIS.PRIMARY_Y)
|
||||
ser2 = chart.add_series(lv.palette_main(lv.PALETTE.GREEN), lv.chart.AXIS.SECONDARY_Y)
|
||||
print(ser2)
|
||||
# Set next points on ser1
|
||||
chart.set_next_value(ser1,10)
|
||||
chart.set_next_value(ser1,10)
|
||||
chart.set_next_value(ser1,10)
|
||||
chart.set_next_value(ser1,10)
|
||||
chart.set_next_value(ser1,10)
|
||||
chart.set_next_value(ser1,10)
|
||||
chart.set_next_value(ser1,10)
|
||||
chart.set_next_value(ser1,30)
|
||||
chart.set_next_value(ser1,70)
|
||||
chart.set_next_value(ser1,90)
|
||||
|
||||
# Directly set points on 'ser2'
|
||||
ser2.y_points = [90, 70, 65, 65, 65, 65, 65, 65, 65, 65]
|
||||
chart.refresh() # Required after direct set
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
pass
|
||||
@@ -1 +0,0 @@
|
||||
pass
|
||||
@@ -1,81 +0,0 @@
|
||||
#!/opt/bin/lv_micropython -i
|
||||
import lvgl as lv
|
||||
|
||||
def event_cb(e):
|
||||
|
||||
code = e.get_code()
|
||||
chart = e.get_target_obj()
|
||||
|
||||
if code == lv.EVENT.VALUE_CHANGED:
|
||||
chart.invalidate()
|
||||
|
||||
if code == lv.EVENT.REFR_EXT_DRAW_SIZE:
|
||||
e.set_ext_draw_size(20)
|
||||
|
||||
elif code == lv.EVENT.DRAW_POST_END:
|
||||
id = chart.get_pressed_point()
|
||||
if id == lv.CHART_POINT_NONE :
|
||||
return
|
||||
|
||||
# print("Selected point {:d}".format(id))
|
||||
|
||||
ser = chart.get_series_next(None)
|
||||
|
||||
while(ser) :
|
||||
p = lv.point_t()
|
||||
chart.get_point_pos_by_id(ser, id, p)
|
||||
# print("point coords: x: {:d}, y: {:d}".format(p.x,p.y))
|
||||
y_array = chart.get_y_array(ser)
|
||||
value = y_array[id]
|
||||
|
||||
buf = lv.SYMBOL.DUMMY + "{:2d}".format(value)
|
||||
|
||||
draw_rect_dsc = lv.draw_rect_dsc_t()
|
||||
draw_rect_dsc.init()
|
||||
draw_rect_dsc.bg_color = lv.color_black()
|
||||
draw_rect_dsc.bg_opa = lv.OPA._50
|
||||
draw_rect_dsc.radius = 3
|
||||
draw_rect_dsc.bg_image_src = buf
|
||||
draw_rect_dsc.bg_image_recolor = lv.color_white()
|
||||
|
||||
coords = lv.area_t()
|
||||
chart.get_coords(coords)
|
||||
# print("coords: x1: {:d}, y1: {:d}".format(coords.x1, coords.y1))
|
||||
a = lv.area_t()
|
||||
a.x1 = coords.x1 + p.x - 20
|
||||
a.x2 = coords.x1 + p.x + 20
|
||||
a.y1 = coords.y1 + p.y - 30
|
||||
a.y2 = coords.y1 + p.y - 10
|
||||
# print("a: x1: {:d}, x2: {:d}, y1: {:d}, y2: {:d}".format(a.x1,a.x2,a.y1,a.y2))
|
||||
draw_ctx = e.get_draw_ctx()
|
||||
draw_ctx.rect(draw_rect_dsc, a)
|
||||
|
||||
ser = chart.get_series_next(ser)
|
||||
|
||||
elif code == lv.EVENT.RELEASED:
|
||||
chart.invalidate()
|
||||
|
||||
|
||||
#
|
||||
# Show the value of the pressed points
|
||||
#
|
||||
|
||||
# Create a chart
|
||||
chart = lv.chart(lv.screen_active())
|
||||
chart.set_size(200, 150)
|
||||
chart.center()
|
||||
|
||||
chart.add_event_cb(event_cb, lv.EVENT.ALL, None)
|
||||
|
||||
chart.refresh_ext_draw_size()
|
||||
|
||||
# Zoom in a little in X
|
||||
#chart.set_scale_x(800)
|
||||
|
||||
# Add two data series
|
||||
ser1 = chart.add_series(lv.palette_main(lv.PALETTE.RED), lv.chart.AXIS.PRIMARY_Y)
|
||||
ser2 = chart.add_series(lv.palette_main(lv.PALETTE.GREEN), lv.chart.AXIS.PRIMARY_Y)
|
||||
for i in range(10):
|
||||
chart.set_next_value(ser1, lv.rand(60, 90))
|
||||
chart.set_next_value(ser2, lv.rand(10, 40))
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
pass
|
||||
@@ -1 +0,0 @@
|
||||
pass
|
||||
@@ -1 +0,0 @@
|
||||
pass
|
||||
@@ -1 +0,0 @@
|
||||
pass
|
||||
@@ -1,30 +0,0 @@
|
||||
import lvgl as lv
|
||||
|
||||
def add_data(t):
|
||||
chart.set_next_value(ser, lv.rand(10, 90))
|
||||
|
||||
p = chart.get_point_count()
|
||||
s = chart.get_x_start_point(ser)
|
||||
a = chart.get_y_array(ser)
|
||||
|
||||
a[(s + 1) % p] = lv.CHART_POINT_NONE
|
||||
a[(s + 2) % p] = lv.CHART_POINT_NONE
|
||||
a[(s + 3) % p] = lv.CHART_POINT_NONE
|
||||
chart.refresh()
|
||||
|
||||
#
|
||||
# Circular line chart with gap
|
||||
#
|
||||
chart = lv.chart(lv.screen_active())
|
||||
|
||||
chart.set_update_mode(lv.chart.UPDATE_MODE.CIRCULAR)
|
||||
chart.set_size(200, 150)
|
||||
chart.center()
|
||||
|
||||
chart.set_point_count(30)
|
||||
ser = chart.add_series(lv.palette_main(lv.PALETTE.RED), lv.chart.AXIS.PRIMARY_Y)
|
||||
#Prefill with data
|
||||
for i in range(0, 30):
|
||||
chart.set_next_value(ser, lv.rand(10, 90))
|
||||
|
||||
lv.timer_create(add_data, 200, None)
|
||||
Reference in New Issue
Block a user