margaid icon indicating copy to clipboard operation
margaid copied to clipboard

set series title

Open BenoitBotton opened this issue 2 years ago • 1 comments
trafficstars

I just discovered margaid and like it very much. However, I cannot see how to set a series title apart from at creation time. I need to set the series title once values have been accumulated and calculation done on these values. is there a way to achieve that?

pseudo code to illustrate:

for i,d:=range data{
   ...
 series[i] = m.NewSeries()
avg=0  
 for j:=0;j<len(data.x);j++{
      somevalue= f(data.y[i])
     avg+=somevalue
     series[i].Add(m.MakeValue(data.x[i],somevalue))
    }
avg:=avg/float64(len(data.x))

series[i].SetTitle("seriesname "+ strconv.FormatFloat(avg, ...)  //how do I achieve this?
}

BenoitBotton avatar Aug 22 '23 13:08 BenoitBotton

hi @BenoitBotton , let me try to follow up on this one.

Indeed the "label" of the series is meant to be given in its creation. But there is a simple workaround:

m.Titled("seriesname "+ strconv.FormatFloat(avg, ...))(series[i])

The margaid.Titled object is supposed to be used as an option to margaid.NewSeries, but one can use the function it returns directly to change a Series configuration. Probably not how it was intended to be used, but ... it works :)

I did a quick demo (that you can interact with if you copy the notebook) here

I hope it helps!

janpfeifer avatar Aug 24 '23 07:08 janpfeifer