Search code examples
layoutlabelpositionlegendanychart

Anychart multiple Legends and Labels


We often show several legends in our charts and usually even a label as footer. The legends can be above or below the chart and thus also the footer. If there is more than one legend, the legends should be drawn stacked up, one above the other.

For this case we use standalone legends and labels.

But we have a problem: Since the legends and the chart are all drawn in the same container, the chart hides the legends. We have solved the problem so that the margin of the chart is adjusted when a legend is drawn underneath it. Now the chart takes less space and you can see the legend as planned. However, this does not work properly if there are several legends or footer.

Standalones cannot be placed with top() or left(), but only have their parent container and a position(). Manipulating the margin of each legend and the chart to fit them all in the container is not a satisfying way to do this.

There must be a better way to control the layouting of the elements within the container.

What is the right way to do this?


Solution

  • The position of standalone legend on the stage can be controlled using parentBounds() function. For details, check the sample.