amcharts / amcharts3

JavaScript Charts V3
Other
395 stars 129 forks source link

Can I truncate long legends on Pie Charts without affects in chart Labels? #153

Open rrubenich opened 6 years ago

rrubenich commented 6 years ago

Following the sample in https://www.amcharts.com/kbase/truncating-long-legend-labels-on-pie-chart/ I can truncate the legends, but when the property labelsEnabled is true, the same short legends are showed as labels.

I've tried to pass this function in the labelFunction:

return function(data) {
    data.title = legendLimit && (legendLimit + 3) < data.title.length
        ? data.title.substr(0, legendLimit) + '...' 
        : data.title;

    return `${data.title}: ${data.value}`;
};

But the behavior persists.

In Pie Charts there is a way to transform only the legends?

martynasma commented 6 years ago

Oh, it's been a while. Sorry for noticing only now. We don't monitor github issues as closely as other support channels.

The solution is very simple.

In the example balloonText is being replaced with something else to display full titles in balloon.

You can do the same with labelText:

chart.balloonText = chart.balloonText.replace(/\[\[title\]\]/, "[["+titleField+"]]");
chart.labelText = chart.balloonText;

Hope this is still helpful.