kivy.garden.graph: How to change x axis ticks from numbers to date or time values in kivy garden graph?

217 views
Skip to first unread message

sirAmin

unread,
Jun 6, 2020, 7:16:03 AM6/6/20
to Kivy users support
I can't change the x-axis of kivy.garden.Graph from numbers to date values or at least change text of x_ticks of the graph.

I want something like this:


Chart-SharePoint-Date-Time-Label-Format-short-date.png


I can create my plot and graph but i don't know how to change x_ticks text values.


from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy_garden.graph import Graph, LinePlot
import math

class MyGrid(GridLayout):

   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)
       
self.cols = 1
       
self.plot = LinePlot(line_width=1.5, color=[1, 0, 0, 1])
       
self.graph = Graph(xlabel='Date', ylabel='Y', x_ticks_minor=5,
                           x_ticks_major
=25, y_ticks_major=1,
                           y_grid_label
=True, x_grid_label=True, padding=5,
                           x_grid
=True, y_grid=True, xmin=0, xmax=200, ymin=-2, ymax=2,
                           x_ticks_angle
=90)

       
self.plot.points = [(x, math.sin(x / 10.)) for x in range(0, 201)]

       
self.graph.add_plot(self.plot)
       
       
self.add_widget(self.graph)

class MyKivy(App):
   
def build(self):
       
return MyGrid()

if __name__ == "__main__":

   
MyKivy().run()


Reply all
Reply to author
Forward
0 new messages