[reportlab-users] How can I stripe the grid
    Ulf Renman 
    ulf.renman at favoptic.com
       
    Thu Nov 12 08:39:27 EST 2009
    
    
  
I solved this myself with the code below. Any comments on that?
weekColors = [
    colors.white,
    colors.white,
    colors.white,
    colors.white,
    colors.white,
    colors.Color(0.7,0.7,0.7),
    colors.Color(0.9,0.7,0.7),
    ]
def fun(data):
    drawing = Drawing(w,h)
    lp = LinePlot()
    <snip>
    # Create the grid.
    #   Use the same size and position as the LinePlot
    #   Calculate the gridstep by checking the actual data
    #   Offset it by half a step to make the grid better aligned with 
the data
    #   Calculate the order of the striping by getting the weekday of 
the first
    #     data point.
    grid = Grid()
    grid.x = lp.x
    grid.y = lp.y
    grid.width = lp.width
    grid.height = lp.height
    grid.delta = 20
    mi = data[0]['date'].toordinal()
    ma = data[-1]['date'].toordinal()
    grid.delta = float(grid.width)/(ma-mi)
    grid.delta0 = grid.delta/2
    wd = int(date.fromordinal(mi).strftime('%u'))-1
    grid.stripeColors = (weekColors+weekColors)[wd:wd+len(weekColors)]
    grid.useLines = 1
    grid.useRects = 1
    grid.strokeWidth = 0.3
    drawing.add(grid)
    # Add the LinePlot after the grid since we want it to be painted on top
    # of the grid.
    drawing.add(lp)
Ulf Renman wrote:
> Hi
>
> I use a LinePlot with dates on the x-axis. How can I make the grid so 
> that the columns for Saturday and Sunday be highligted?
>
> /Ulf
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at lists2.reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
    
    
More information about the reportlab-users
mailing list