[reportlab-users] Pass legend labels into LinePlot

Robin Becker robin at reportlab.com
Tue Aug 30 06:47:39 EDT 2016


On 23/08/2016 23:38, Bill Marcum wrote:
> Any help here?  More details:
>
> I'm modeling my code after one of the LinePlot examples.  In that example,
> in the __init__ method, the code does something similar to this:
>
>        sNames = ['Fund1','Fund2','Fund3','Fund4']
>         colorsList = [ lightgrey, grey, darkgrey, lightblue ]
>         for i in range(len(sNames)):
>             self.chart.lines[i].name=sNames[i]
>             self.chart.lines[i].strokeColor=colorsList[i]
>             self.legend.colorNamePairs.append( (colorsList[i], sNames[i]))
>
>
> And this works great, the chart renders with a Legend for those four Funds,
> appropriately color coded.  BUT, this isn't useful to me, I need to pass in
> the labels dynamically, the same way I do the line data in the 'chart.data'
> param.    I can't find a parameter to use that would support this, and the
> param data isn't available during the __init__ method anyway (not sure when
> that gets set, or how to access it).
>
........

It's not clear what you mean by dynamically.

You can always do

self.legend.colorNamePairs = [......]

at any time. That is dynamic.

All of the properties of a drawing can be altered even after it has been drawn 
one or more times. Whether or not the changes are consistent depends on the values.
-- 
Robin Becker


More information about the reportlab-users mailing list