swimlane / ngx-charts

:bar_chart: Declarative Charting Framework for Angular
https://swimlane.github.io/ngx-charts/
MIT License
4.28k stars 1.15k forks source link

Legend outside parent #1248

Open Liero opened 4 years ago

Liero commented 4 years ago

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 commented 4 years ago

Is there any workaround?

Lyelt commented 4 years ago

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).

gary-holland commented 4 years ago

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

beckyarauz commented 4 years ago

I have the exact issue

manolait commented 4 years ago

+1

vishnu-dev commented 4 years ago

Please do something about this.

marco-martins commented 4 years ago

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

ezekiel747 commented 4 years ago

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

AJAnderhub commented 4 years ago

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

danverde commented 4 years ago

I'm running into this issue as well

jarias0811 commented 4 years ago

Same issue here, is incredible something like this is happening

ChelloApps commented 4 years ago

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!

manolait commented 4 years ago

I have the exact issue

simpros commented 2 years ago

Same here...

Any updates on this?

ADEPTYS commented 2 years ago

Faced the same issue, any updates on this?

mperlines commented 2 years ago

Any news related to this topic? Having the same problem

friedrichroell commented 2 years ago

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

megla-cschroepfer commented 1 year ago

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

logitimate commented 1 year ago

Same issue as well.

Liero commented 1 year ago

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

JonathanJPereira commented 1 year ago

Same problem here

mikeelsom commented 1 year ago

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

.chart-legend {
  display: inline-block;
}
Basmatayeh commented 1 year ago

this workaround worked with me

ketka82uk commented 1 year ago

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

.ngx-charts-outer { display: flex }

megla-cschroepfer commented 1 year ago

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?

awdorrin commented 11 months ago

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.

reubenturk-ga commented 4 months ago

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

ali-alamine commented 3 months ago

any updates on this?

ali-alamine commented 3 months ago

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