swimlane / ngx-charts

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

Angular Universal server rendering error: Cannot read property 'width' of undefined #1431

Open dejanGH opened 4 years ago

dejanGH commented 4 years ago

Describe the bug When using ngx-charts with Angular Universal I'm getting an error while server rendering is happening

ERROR TypeError: Cannot read property 'width' of undefined
    at LineChartComponent_Template

ngx-charts version 14.0.0

Additional context Angular version "@angular/core": "~9.1.3"

    <ngx-charts-line-chart [scheme]="colorScheme" [legend]="legend" [showXAxisLabel]="showXAxisLabel"
                    [legendTitle]="'legend'|translate" [legendPosition]="'below'" [showYAxisLabel]="showYAxisLabel"
                    [showXAxisLabel]="showYAxisLabel" [xAxis]="xAxis" [yAxis]="yAxis" [yAxisLabel]="'logs' | translate"
                    [xAxisLabel]="'time' | translate" [timeline]="false" [results]="logChartData">
    </ngx-charts-line-chart>

  legend: boolean = true;
  showLabels: boolean = true;
  animations: boolean = true;
  xAxis: boolean = true;
  yAxis: boolean = true;
  showYAxisLabel: boolean = true;
  showXAxisLabel: boolean = true;
  timeline: boolean = true;
Phe0 commented 4 years ago

I had the same problem running the production build, but not in the develpment build. It seems that it's not working without the view property as it says in the documentation. You have to pass a value to it, if you pass an empty array it will default to [700, 300]

GodSkomis commented 1 year ago

Probably your logChartData isn't an array. Example of inputs can be found there I think this issue may be closed.