Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force pie chart width to cater for dynamic legend width to prevent legend clipping? #1535

Closed
binaryartifex opened this issue May 23, 2024 · 2 comments

Comments

@binaryartifex
Copy link

Question

Is there a way to either

  1. force the pie chart to adapt to the width of the legend or
  2. format pie chart legend labels to be multiline?

i have a limited amount of space within the widget this chart is rendered so either way will help.

without setting anything...you can see the 'kg' unit has been clipped at the boundary of the component. Ideally id prefer that the legend does not clip and instead force the pie chart width to adjust to cater for the change.

image

so as a temp fix ive guestimated a min width for the legend for the moment however larger numbers are also going to inevitably clip off the side. Now when i try to create a custom label adapter with the '\n' value to create new lines...i get the below wierdness where it doesn't wrap back to the start of the new line.

image

for context, this is the adapter im using for the pie chart legend label

    legend.valueLabels.template.adapters.add("text", function (_, target) {
      if (target.dataItem && transform) {
        const item = (target.dataItem as am5.DataItem<IPieSeriesDataItem>).get("value");
        return item ? `\n[bold]${transform(item)}[/]` : undefined;
      }
      return undefined;
    });

Environment (if applicable)

  • amCharts 5.9.8
  • Chrome 125.0.6422.76
  • React 18.3.1
@martynasma
Copy link
Collaborator

Would you be able to post your whole chart and data on CodePen/jsFiddle so that we can test?

Copy link

This issue is stale because it has been open 30 days with no activity. It will be closed in 5 days unless a new comment is added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants