Browse Source

Add formatting to the DateY X axis label

Allow formatting other than the default for the X axis on the DateY plots.
This is done by setting
datey.x_label_format = "%Y-%m-%d"

The formatting is done by the strftime function, so any valid format will work.
See: http://docs.python.org/2/library/time.html#time.strftime
pull/89/head
Phil 11 years ago
parent
commit
9a81e48aeb
  1. 3
      pygal/config.py
  2. 3
      pygal/graph/datey.py

3
pygal/config.py

@ -213,6 +213,9 @@ class Config(object):
y_label_rotation = Key( y_label_rotation = Key(
0, int, "Label", "Specify y labels rotation angles", "in degrees") 0, int, "Label", "Specify y labels rotation angles", "in degrees")
x_label_format = Key(
"%Y-%m-%d %H:%M:%S.%f", str, "Label", "Date format for strftime to display the DateY X labels")
############ Value ############ ############ Value ############
human_readable = Key( human_readable = Key(
False, bool, "Value", "Display values in human readable format", False, bool, "Value", "Display values in human readable format",

3
pygal/graph/datey.py

@ -50,7 +50,8 @@ class DateY(XY):
def _todate(self, d): def _todate(self, d):
""" Converts a number to a date """ """ Converts a number to a date """
return str(self._offset + datetime.timedelta(seconds=d or 0)) currDateTime = self._offset + datetime.timedelta(seconds=d or 0)
return currDateTime.strftime( self.x_label_format )
def _tonumber(self, d): def _tonumber(self, d):
""" Converts a date to a number """ """ Converts a date to a number """

Loading…
Cancel
Save