简体   繁体   中英

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?

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("_"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM