acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_example_chart_3.py (1846B)

      1 def 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
     13 chart = lv.chart(lv.scr_act())
     14 chart.set_size(200, 150)
     15 chart.center()
     16 chart.set_type(lv.chart.TYPE.BAR)
     17 chart.set_range(lv.chart.AXIS.PRIMARY_Y, 0, 100)
     18 chart.set_range(lv.chart.AXIS.SECONDARY_Y, 0, 400)
     19 chart.set_point_count(12)
     20 chart.add_event_cb(draw_event_cb, lv.EVENT.DRAW_PART_BEGIN, None)
     21 
     22 # Add ticks and label to every axis
     23 chart.set_axis_tick(lv.chart.AXIS.PRIMARY_X, 10, 5, 12, 3, True, 40)
     24 chart.set_axis_tick(lv.chart.AXIS.PRIMARY_Y, 10, 5, 6, 2, True, 50)
     25 chart.set_axis_tick(lv.chart.AXIS.SECONDARY_Y, 10, 5, 3, 4,True, 50)
     26 
     27 # Zoom in a little in X
     28 chart.set_zoom_x(800)
     29 
     30 # Add two data series
     31 ser1 = lv.chart.add_series(chart, lv.palette_lighten(lv.PALETTE.GREEN, 2), lv.chart.AXIS.PRIMARY_Y)
     32 ser2 = 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'
     35 chart.set_next_value(ser1, 31)
     36 chart.set_next_value(ser1, 66)
     37 chart.set_next_value(ser1, 10)
     38 chart.set_next_value(ser1, 89)
     39 chart.set_next_value(ser1, 63)
     40 chart.set_next_value(ser1, 56)
     41 chart.set_next_value(ser1, 32)
     42 chart.set_next_value(ser1, 35)
     43 chart.set_next_value(ser1, 57)
     44 chart.set_next_value(ser1, 85)
     45 chart.set_next_value(ser1, 22)
     46 chart.set_next_value(ser1, 58)
     47 
     48 # Directly set points on 'ser2'
     49 ser2.y_points = [92,71,61,15,21,35,35,58,31,53,33,73]
     50 
     51 chart.refresh()  # Required after direct set
     52