Strawberry
Strawberry

Reputation: 67888

How can I add a custom class to the AmChart legend?

I want to wrap a html tag around the labels in the legend. I looked through the documentation for AmLegend(), and I didn't find anything immediately obvious. Is there a way to do this?

Upvotes: 3

Views: 1726

Answers (1)

Maertz
Maertz

Reputation: 4952

the legend comes already with "amChartsLegend" but if you prefer your own classNames you can access it within the created chart instance "legendDiv"

var chart = AmCharts.makeChart({...});
chart.legendDiv.classList.add('your-classname');

i hope that helped :)

UPDATE

Ensure the browser supports the "classList" feature otherwise you need to add a polyfill for that.

Here is a one-liner to check the support to add the polyfill or not. ("classList" in document.createElement("_"))

Upvotes: 1

Related Questions