Dynamic legends and number of decimals

We recently got a support email about legends in graphs. Namely, how to get dynamic legends and how to control decimals when presenting numbers.

First let’s look at how to create a dynamic legend. You have two parameter as input. An instrument name and a number of days to display its history.

out series<date>(number) test(instrument_name in, number days){
	return series(d:today() - days, today(); instrument(in, d, "Mid").quote());
}

will give your this graph:

Now, double-click on the graph-line or the legend “test-1”. To open the formatting dialog.

You can now change the legend by writing free text and include the available parameters included in curly brackets { param } to create a dynamic legend.

To control the number of decimals for the numeric “days” in this example. You can use {0days} to set number of decimals to zero. I.e. an integer before the numeric parameter controls the decimals.

1 Like