ngx-charts icon indicating copy to clipboard operation
ngx-charts copied to clipboard

Legend outside parent

Open Liero opened this issue 5 years ago • 29 comments

If I place linechart inside parent with fixed height and set legendPosition="below", the legend is acually outside the parent:

To Reproduce

<div style="position: relative; height: 500px; background: lightsalmon">
  <ngx-charts-line-chart [results]="data" [legend]="true" [xAxis]="true"
     [yAxis]="true" legendPosition="below">
   </ngx-charts-line-chart>
</div>

Screenshots image

Expected behavior Legend should be inside parent, otherwise it does not make any sense.

ngx-charts version

"@swimlane/ngx-charts": "^12.0.1", "@angular/core": "~7.2.0",

Liero avatar Aug 14 '19 07:08 Liero

Is there any workaround?

Liero avatar Aug 14 '19 07:08 Liero

I'm experiencing the same behavior. It seems rather undesirable to have to manually add padding to the container if I don't want the legend overlapping the content below the chart.

Not to mention that adding padding seems to break the responsiveness of the chart altogether (not surprising - I've seen that issue mentioned elsewhere).

Lyelt avatar Aug 15 '19 19:08 Lyelt

I'm having similar problems with the chart infinitely resizing when legend is set "below". Here is a stackblitz for reference:

https://ngx-chart-in-flex-c6sutq.stackblitz.io

gary-holland avatar Aug 25 '19 02:08 gary-holland

I have the exact issue

beckyarauz avatar Nov 20 '19 10:11 beckyarauz

+1

manolait avatar Nov 25 '19 17:11 manolait

Please do something about this.

vishnu-dev avatar Dec 02 '19 06:12 vishnu-dev

I have the same problem. But it's curious because seems to work properly in the page example. https://swimlane.github.io/ngx-charts/#/ngx-charts/line-chart

marco-martins avatar Feb 13 '20 15:02 marco-martins

is there any update on this? would be very useful to have it working. Thanks!

ezekiel747 avatar Mar 23 '20 14:03 ezekiel747

I am also having the same problem. Is there a workaround at least?

AJAnderhub avatar Apr 23 '20 07:04 AJAnderhub

I'm running into this issue as well

danverde avatar Apr 27 '20 15:04 danverde

Same issue here, is incredible something like this is happening

jarias0811 avatar Apr 28 '20 22:04 jarias0811

Same problem here, I'm defining chart sizes in a configuration utility and this bug is then causing positioning to be incorrect for charts where the Legend is configured for 'below' display!

ChelloApps avatar Jun 22 '20 11:06 ChelloApps

I have the exact issue

manolait avatar Jul 02 '20 10:07 manolait

Same here...

Any updates on this?

simpros avatar Aug 17 '21 10:08 simpros

Faced the same issue, any updates on this?

ADEPTYS avatar Oct 29 '21 20:10 ADEPTYS

Any news related to this topic? Having the same problem

mperlines avatar Nov 02 '21 11:11 mperlines

im at "version": "20.1.0" and im facing the same problem. Would be amazing and hugely appreciated if this got fixed! :)

friedrichroell avatar May 27 '22 21:05 friedrichroell

I am facing the same problem and could not find any reliable solution. When will a fix be available?

megla-cschroepfer avatar Nov 22 '22 12:11 megla-cschroepfer

Same issue as well.

logitimate avatar Dec 20 '22 22:12 logitimate

Due to lack of support I recommend to find another charting components

Liero avatar Dec 21 '22 10:12 Liero

Same problem here

JonathanJPereira avatar Dec 27 '22 17:12 JonathanJPereira

Adding this to a global style sheet solved the issue for me

.chart-legend {
  display: inline-block;
}

mikeelsom avatar Feb 15 '23 14:02 mikeelsom

this workaround worked with me

  • increase the bottom padding of the div wrapper.

Basmatayeh avatar Mar 06 '23 16:03 Basmatayeh

Adding this to global stylesheet is what fixed for me (couldn't get legend on right)

.ngx-charts-outer { display: flex }

ketka82uk avatar Mar 23 '23 16:03 ketka82uk

I just came across this problem yet again. None of the suggested fixes seems to work in my case so far because I am using the chart for an Angular element which is used inside another application. Any updates or other workarounds?

megla-cschroepfer avatar May 10 '23 09:05 megla-cschroepfer

This seems to be a result of the height and width being applied to both the outer div and svg without accounting for the height of the legend.

<div class="ngx-charts-outer" style=width; 600px; height: 400px;">
  <svg class="ngx-charts" width="600" height="400">...

I worked around this by adding bottom-padding to a wrapper div, but I think the style on the ngx-charts-outer should be removed and placed in the css, making the height auto.

awdorrin avatar Jul 27 '23 13:07 awdorrin

I can confirm @awdorrin 's findings.

Although we're talking a different root cause from the original post now, this current breakage seems to have happened at https://github.com/swimlane/ngx-charts/commit/91acd8d111af65af226f81805bdc30c2081bd3b9

reubenturk-ga avatar Mar 08 '24 05:03 reubenturk-ga

any updates on this?

ali-alamine avatar Mar 14 '24 10:03 ali-alamine

adding this to the global style sheet does the trick but seems to break the responsiveness : .chart-legend{ display: block !important; }

ali-alamine avatar Mar 14 '24 10:03 ali-alamine