1def draw_event_cb(e): 2 3 dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param()) 4 if dsc.part == lv.PART.TICKS and dsc.id == lv.chart.AXIS.PRIMARY_X: 5 month = ["Jan", "Febr", "March", "Apr", "May", "Jun", "July", "Aug", "Sept", "Oct", "Nov", "Dec"] 6 # dsc.text is defined char text[16], I must therefore convert the Python string to a byte_array 7 dsc.text = bytes(month[dsc.value],"ascii") 8# 9# Add ticks and labels to the axis and demonstrate scrolling 10# 11 12# Create a chart 13chart = lv.chart(lv.scr_act()) 14chart.set_size(200, 150) 15chart.center() 16chart.set_type(lv.chart.TYPE.BAR) 17chart.set_range(lv.chart.AXIS.PRIMARY_Y, 0, 100) 18chart.set_range(lv.chart.AXIS.SECONDARY_Y, 0, 400) 19chart.set_point_count(12) 20chart.add_event_cb(draw_event_cb, lv.EVENT.DRAW_PART_BEGIN, None) 21 22# Add ticks and label to every axis 23chart.set_axis_tick(lv.chart.AXIS.PRIMARY_X, 10, 5, 12, 3, True, 40) 24chart.set_axis_tick(lv.chart.AXIS.PRIMARY_Y, 10, 5, 6, 2, True, 50) 25chart.set_axis_tick(lv.chart.AXIS.SECONDARY_Y, 10, 5, 3, 4,True, 50) 26 27# Zoom in a little in X 28chart.set_zoom_x(800) 29 30# Add two data series 31ser1 = lv.chart.add_series(chart, lv.palette_lighten(lv.PALETTE.GREEN, 2), lv.chart.AXIS.PRIMARY_Y) 32ser2 = lv.chart.add_series(chart, lv.palette_darken(lv.PALETTE.GREEN, 2), lv.chart.AXIS.SECONDARY_Y) 33 34# Set the next points on 'ser1' 35chart.set_next_value(ser1, 31) 36chart.set_next_value(ser1, 66) 37chart.set_next_value(ser1, 10) 38chart.set_next_value(ser1, 89) 39chart.set_next_value(ser1, 63) 40chart.set_next_value(ser1, 56) 41chart.set_next_value(ser1, 32) 42chart.set_next_value(ser1, 35) 43chart.set_next_value(ser1, 57) 44chart.set_next_value(ser1, 85) 45chart.set_next_value(ser1, 22) 46chart.set_next_value(ser1, 58) 47 48# Directly set points on 'ser2' 49ser2.y_points = [92,71,61,15,21,35,35,58,31,53,33,73] 50 51chart.refresh() # Required after direct set 52 53