swimlane / ngx-charts

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

Height, Width and Padding are going nutz! #514

Open vbenavidesa opened 7 years ago

vbenavidesa commented 7 years ago

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here

So ngx-charts is great to use most of the time. my request goes to get a variable to set the height and width independently, I am having a lot of issues on getting the tables to display properly with the automatic solution you have, as my container is dynamic on height it goes to 0 when I insert the chart only, so I have to manually set a height which then goes nutz with the charts axis labels. Another big issues is padding, I saw #225 but if I put another div inside my html it makes the chart HUGE! and doesnt work as a workaround, I use INSPINA dashboard SPA which has some small white boxes called ibox that holds stuff like widgets but the chart goes insane inside it.

So basically I would love 2 features:

marjan-georgiev commented 7 years ago

I'm not sure what you mean by padding option? The just simply expands to fill the size of it's parent container. The parent container should have a height already set, and no padding.

vbenavidesa commented 7 years ago

Hi marjan,

Widgster actually has no height set and it adapts to the information you place inside. That is why I was wondering if you will implement an independent width and height feature.

On the padding option, the graphic just gets to the very edge of the widget and the legend sticks out just a bit. if you have an email I can provide some screenshots.

marjan-georgiev commented 7 years ago

You could try wrapping the chart in a div which does not have any padding. The div will also need to have its height set, otherwise the auto size will not work.

alex88 commented 6 years ago

In my case, having set [view]="[100,100]" doesn't set the chart to be 100x100 but just the container and the graph has quite some padding

screen shot 2017-12-11 at 11 01 25 am

is there a way to not have that padding? At the end the g element that contains the graph is 60x60, which wastes 40% of the space

dezudas commented 6 years ago

@alex88 I had similar issue, I am getting extra space in bar and pie chart which is killing space of my container.

iliyaisd commented 6 years ago

+1 to the request, having the same issue. Struggled with Pie Grid and finally just had to copy/paste and redefine it in a separate component, changing the following things:

piegrid

It would be nice to have those things customizable with inputs. Thank you for a nice library!

@marjan-georgiev

mnasyrov commented 6 years ago

I'm using a following workaround for ngx-chart v7.4 that sets chart's margins in ngAfterViewInit:

import {PieChartComponent} from '@swimlane/ngx-charts';

@Component()
export class MyPage {
    @ViewChild(PieChartComponent) pieChart: PieChartComponent;

    ngAfterViewInit() {
        setTimeout(() => {
            this.pieChart.margin = [0, 0, 0, 0];
            this.pieChart.update();
        }, 0);
    }
}
soothran commented 6 years ago

I'm getting the following error. cannot set property 'margin' of undefined.

I've included the above code snippet in my component.

@mnasyrov could you please elaborate your code implementation? Thanks

soothran commented 6 years ago

I got this working by increasing timout

mnasyrov commented 6 years ago

I made another workaround by using a directive which can do the same without timeouts.

import {Directive, Self} from '@angular/core';
import {PieChartComponent} from '@swimlane/ngx-charts';

@Directive({
    selector: 'ngx-charts-pie-chart[hotfix-zero-margin]'
})
export class NgxPieChartZeroMarginDirective {
    constructor(@Self() pieChart: PieChartComponent) {
        pieChart.margin = [0, 0, 0, 0];
    }
}
furevor commented 5 years ago

I made another workaround by using a directive which can do the same without timeouts.

import {Directive, Self} from '@angular/core';
import {PieChartComponent} from '@swimlane/ngx-charts';

@Directive({
    selector: 'ngx-charts-pie-chart[hotfix-zero-margin]'
})
export class NgxPieChartZeroMarginDirective {
    constructor(@Self() pieChart: PieChartComponent) {
        pieChart.margin = [0, 0, 0, 0];
    }
}

Hello! Thank you for this workaround, but it looks like that now it doesn't work. Maybe any other ideas?

P.S. I am talking about BarVerticalComponent

P.P.S. I am sorry, this workaround should work for pie chart, but not for bar chart..

AaronLavers commented 4 years ago

I made another workaround by using a directive which can do the same without timeouts.

import {Directive, Self} from '@angular/core';
import {PieChartComponent} from '@swimlane/ngx-charts';

@Directive({
    selector: 'ngx-charts-pie-chart[hotfix-zero-margin]'
})
export class NgxPieChartZeroMarginDirective {
    constructor(@Self() pieChart: PieChartComponent) {
        pieChart.margin = [0, 0, 0, 0];
    }
}

I've just tried to implement this directive in ngx-charts 12.0.1, and for anyone else trying you need to make a small change to 'margin', instead making it 'margins'

pieChart.margins = [0, 0, 0, 0];

This seems to work quite well. It would be really good if the Swimlane team could implement the margins as an input however.