This short tutorial will show the steps involved in dynamically changing position of the legend.
Changing position
The following steps are involved when changing the position of the legend, e.g. from bottom to left:
- Move the legend's position in the
chart.children
list as/if needed. - Change chart's layout to horizontal if required.
- Update settings of the legend so they are suitable for new layout.
For example, the below code will move the legend from bottom, to left:
chart.children.moveValue(legend, 0); chart.set("layout", root.horizontalLayout); legend.setAll({ x: 0, centerX: 0, centerY: am5.p50, y: am5.p50, layout: root.verticalLayout });
chart.children.moveValue(legend, 0); chart.set("layout", root.horizontalLayout); legend.setAll({ x: 0, centerX: 0, centerY: am5.p50, y: am5.p50, layout: root.verticalLayout });
Demo
See the Pen Dynamically changing legend position by amCharts team (@amcharts) on CodePen.