Skip to content

Dropdown control

It’s a generic control that can be added to a stock toolbar, populated with custom content to be displayed in a dropdown when toggled.

Like any other control, it should be instantiated using new() syntax, and pushed into toolbar’s controls list:

// Add custom dropdown
let myDropdown = am5stock.DropdownControl.new(root, {
stockChart: stockChart
});
// Add toolbar
let toolbar = am5stock.StockToolbar.new(root, {
container: document.getElementById("chartcontrols"),
stockChart: stockChart,
controls: [
myDropdown
]
});

The above code will add a control. Now let’s see how we can add content to its dropdown popup.

We can supply plain HTML to add, or append DOM nodes.

We can use control’s html setting to supply content:

let myDropdown = am5stock.DropdownControl.new(root, {
stockChart: stockChart,
html: "<h3>Hello world!</h3>"
});

We can also push DOM nodes directly to control’s container:

let myDropdown = am5stock.DropdownControl.new(root, {
stockChart: stockChart,
name: "My Button"
});
let dropdownContent = document.createElement("div");
dropdownContent.innerHTML = "<h3>Hello World!</h3>";
myDropdown.getPrivate("container").appendChild(dropdownContent);
Open in CodePen