Kendo UI for Angular Pie Charts is not responsive with ChangeDetectionStrategy.OnPush










0















I have created a new component that should show a pie chart inside any place that I place that component, the problem is even with simple component, the pie chart stays as the size of the first render, I got this issue after I changed ChangeDetectionStrategy to ChangeDetectionStrategy.OnPush, the problem that I did that because without even the problem does not persist but the resizing start to be laggy and consume more CPU usage during that.



So I got the option to keep that lag and make chart responsive, or change the ChangeDetectionStrategy and get chart stuck to first time render.



Also, I got many types of charts, like the bar chart and the issue does not seem to be happening with that kind of charts, for now, it is only for my Pie chart.



my.component.ts:



import ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit from '@angular/core';

@Component(
selector: 'my-component',
templateUrl: 'my-component.html',
styleUrls: ['./my-component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
)
export class MyComponent implements OnInit
public pieData: category: string; value: number; active: boolean = [
category: 'Complete', value: 123,
category: 'Work In Progress', value: 22,
category: 'Other', value: 5,
];
constructor(private _cdRef: ChangeDetectorRef)




my-component.html:



<kendo-chart [seriesColors]="['orange', '#ffe', 'green']">
<kendo-chart-legend position="top"></kendo-chart-legend>
<kendo-chart-series>
<kendo-chart-series-item [type]="'pie'" [data]="pieData" [field]="'value'" [categoryField]="'category'">
</kendo-chart-series-item>
</kendo-chart-series>
</kendo-chart>


my-component.scss:



:host 
display: flex;
overflow: hidden;
margin: 8px;
padding: 8px;
flex-direction: column;

@media only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px)
padding: 2px;











share|improve this question






















  • The pie chart seems to be resized correctly here: stackblitz.com/edit/angular-jd47bi?file=app%2Fapp.component.ts Is there anything else specific besides the OnPush strategy?

    – SiliconSoul
    Nov 16 '18 at 3:33











  • @SiliconSoul well, nothing else, I'm using this chart inside some containers with flex layout, but these containers working well, I mean they got resized so I'm not sure if that's the problem, also the chart is inside an Ionic application. but for the component itself, got nothing else.

    – Al-Mothafar
    Nov 16 '18 at 7:18












  • I'll try to provide the containers template once I have access to code.

    – Al-Mothafar
    Nov 16 '18 at 7:19















0















I have created a new component that should show a pie chart inside any place that I place that component, the problem is even with simple component, the pie chart stays as the size of the first render, I got this issue after I changed ChangeDetectionStrategy to ChangeDetectionStrategy.OnPush, the problem that I did that because without even the problem does not persist but the resizing start to be laggy and consume more CPU usage during that.



So I got the option to keep that lag and make chart responsive, or change the ChangeDetectionStrategy and get chart stuck to first time render.



Also, I got many types of charts, like the bar chart and the issue does not seem to be happening with that kind of charts, for now, it is only for my Pie chart.



my.component.ts:



import ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit from '@angular/core';

@Component(
selector: 'my-component',
templateUrl: 'my-component.html',
styleUrls: ['./my-component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
)
export class MyComponent implements OnInit
public pieData: category: string; value: number; active: boolean = [
category: 'Complete', value: 123,
category: 'Work In Progress', value: 22,
category: 'Other', value: 5,
];
constructor(private _cdRef: ChangeDetectorRef)




my-component.html:



<kendo-chart [seriesColors]="['orange', '#ffe', 'green']">
<kendo-chart-legend position="top"></kendo-chart-legend>
<kendo-chart-series>
<kendo-chart-series-item [type]="'pie'" [data]="pieData" [field]="'value'" [categoryField]="'category'">
</kendo-chart-series-item>
</kendo-chart-series>
</kendo-chart>


my-component.scss:



:host 
display: flex;
overflow: hidden;
margin: 8px;
padding: 8px;
flex-direction: column;

@media only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px)
padding: 2px;











share|improve this question






















  • The pie chart seems to be resized correctly here: stackblitz.com/edit/angular-jd47bi?file=app%2Fapp.component.ts Is there anything else specific besides the OnPush strategy?

    – SiliconSoul
    Nov 16 '18 at 3:33











  • @SiliconSoul well, nothing else, I'm using this chart inside some containers with flex layout, but these containers working well, I mean they got resized so I'm not sure if that's the problem, also the chart is inside an Ionic application. but for the component itself, got nothing else.

    – Al-Mothafar
    Nov 16 '18 at 7:18












  • I'll try to provide the containers template once I have access to code.

    – Al-Mothafar
    Nov 16 '18 at 7:19













0












0








0








I have created a new component that should show a pie chart inside any place that I place that component, the problem is even with simple component, the pie chart stays as the size of the first render, I got this issue after I changed ChangeDetectionStrategy to ChangeDetectionStrategy.OnPush, the problem that I did that because without even the problem does not persist but the resizing start to be laggy and consume more CPU usage during that.



So I got the option to keep that lag and make chart responsive, or change the ChangeDetectionStrategy and get chart stuck to first time render.



Also, I got many types of charts, like the bar chart and the issue does not seem to be happening with that kind of charts, for now, it is only for my Pie chart.



my.component.ts:



import ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit from '@angular/core';

@Component(
selector: 'my-component',
templateUrl: 'my-component.html',
styleUrls: ['./my-component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
)
export class MyComponent implements OnInit
public pieData: category: string; value: number; active: boolean = [
category: 'Complete', value: 123,
category: 'Work In Progress', value: 22,
category: 'Other', value: 5,
];
constructor(private _cdRef: ChangeDetectorRef)




my-component.html:



<kendo-chart [seriesColors]="['orange', '#ffe', 'green']">
<kendo-chart-legend position="top"></kendo-chart-legend>
<kendo-chart-series>
<kendo-chart-series-item [type]="'pie'" [data]="pieData" [field]="'value'" [categoryField]="'category'">
</kendo-chart-series-item>
</kendo-chart-series>
</kendo-chart>


my-component.scss:



:host 
display: flex;
overflow: hidden;
margin: 8px;
padding: 8px;
flex-direction: column;

@media only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px)
padding: 2px;











share|improve this question














I have created a new component that should show a pie chart inside any place that I place that component, the problem is even with simple component, the pie chart stays as the size of the first render, I got this issue after I changed ChangeDetectionStrategy to ChangeDetectionStrategy.OnPush, the problem that I did that because without even the problem does not persist but the resizing start to be laggy and consume more CPU usage during that.



So I got the option to keep that lag and make chart responsive, or change the ChangeDetectionStrategy and get chart stuck to first time render.



Also, I got many types of charts, like the bar chart and the issue does not seem to be happening with that kind of charts, for now, it is only for my Pie chart.



my.component.ts:



import ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit from '@angular/core';

@Component(
selector: 'my-component',
templateUrl: 'my-component.html',
styleUrls: ['./my-component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
)
export class MyComponent implements OnInit
public pieData: category: string; value: number; active: boolean = [
category: 'Complete', value: 123,
category: 'Work In Progress', value: 22,
category: 'Other', value: 5,
];
constructor(private _cdRef: ChangeDetectorRef)




my-component.html:



<kendo-chart [seriesColors]="['orange', '#ffe', 'green']">
<kendo-chart-legend position="top"></kendo-chart-legend>
<kendo-chart-series>
<kendo-chart-series-item [type]="'pie'" [data]="pieData" [field]="'value'" [categoryField]="'category'">
</kendo-chart-series-item>
</kendo-chart-series>
</kendo-chart>


my-component.scss:



:host 
display: flex;
overflow: hidden;
margin: 8px;
padding: 8px;
flex-direction: column;

@media only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px)
padding: 2px;








angular angular-components kendo-chart kendo-angular-ui






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 12:44









Al-MothafarAl-Mothafar

4,04534674




4,04534674












  • The pie chart seems to be resized correctly here: stackblitz.com/edit/angular-jd47bi?file=app%2Fapp.component.ts Is there anything else specific besides the OnPush strategy?

    – SiliconSoul
    Nov 16 '18 at 3:33











  • @SiliconSoul well, nothing else, I'm using this chart inside some containers with flex layout, but these containers working well, I mean they got resized so I'm not sure if that's the problem, also the chart is inside an Ionic application. but for the component itself, got nothing else.

    – Al-Mothafar
    Nov 16 '18 at 7:18












  • I'll try to provide the containers template once I have access to code.

    – Al-Mothafar
    Nov 16 '18 at 7:19

















  • The pie chart seems to be resized correctly here: stackblitz.com/edit/angular-jd47bi?file=app%2Fapp.component.ts Is there anything else specific besides the OnPush strategy?

    – SiliconSoul
    Nov 16 '18 at 3:33











  • @SiliconSoul well, nothing else, I'm using this chart inside some containers with flex layout, but these containers working well, I mean they got resized so I'm not sure if that's the problem, also the chart is inside an Ionic application. but for the component itself, got nothing else.

    – Al-Mothafar
    Nov 16 '18 at 7:18












  • I'll try to provide the containers template once I have access to code.

    – Al-Mothafar
    Nov 16 '18 at 7:19
















The pie chart seems to be resized correctly here: stackblitz.com/edit/angular-jd47bi?file=app%2Fapp.component.ts Is there anything else specific besides the OnPush strategy?

– SiliconSoul
Nov 16 '18 at 3:33





The pie chart seems to be resized correctly here: stackblitz.com/edit/angular-jd47bi?file=app%2Fapp.component.ts Is there anything else specific besides the OnPush strategy?

– SiliconSoul
Nov 16 '18 at 3:33













@SiliconSoul well, nothing else, I'm using this chart inside some containers with flex layout, but these containers working well, I mean they got resized so I'm not sure if that's the problem, also the chart is inside an Ionic application. but for the component itself, got nothing else.

– Al-Mothafar
Nov 16 '18 at 7:18






@SiliconSoul well, nothing else, I'm using this chart inside some containers with flex layout, but these containers working well, I mean they got resized so I'm not sure if that's the problem, also the chart is inside an Ionic application. but for the component itself, got nothing else.

– Al-Mothafar
Nov 16 '18 at 7:18














I'll try to provide the containers template once I have access to code.

– Al-Mothafar
Nov 16 '18 at 7:19





I'll try to provide the containers template once I have access to code.

– Al-Mothafar
Nov 16 '18 at 7:19












1 Answer
1






active

oldest

votes


















0














If you got component with changeDetection: ChangeDetectionStrategy.OnPush (which is a good idea to improve performance) then the good solution is to get markForCheck() fired each time you resize the window, but with debounceTime so you will get some time to wait before you resize the chart:



import ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit from '@angular/core';
import fromEvent from 'rxjs';
import debounceTime from 'rxjs/operators';

@Component(
selector: 'my-component',
templateUrl: 'my-component.html',
styleUrls: ['./my-component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
)
export class MyComponent implements OnInit
constructor(private _cdRef: ChangeDetectorRef)


ngOnInit(): void
fromEvent(window, 'resize') // get the event observable
.pipe(debounceTime(200)) // you can change debounceTime to whatever you want
.subscribe((event) =>
this._cdRef.markForCheck(); // Here we go
);




As the chart itself seems to be responsive and should be redrawn each window change, this will do the trick.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300539%2fkendo-ui-for-angular-pie-charts-is-not-responsive-with-changedetectionstrategy-o%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    If you got component with changeDetection: ChangeDetectionStrategy.OnPush (which is a good idea to improve performance) then the good solution is to get markForCheck() fired each time you resize the window, but with debounceTime so you will get some time to wait before you resize the chart:



    import ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit from '@angular/core';
    import fromEvent from 'rxjs';
    import debounceTime from 'rxjs/operators';

    @Component(
    selector: 'my-component',
    templateUrl: 'my-component.html',
    styleUrls: ['./my-component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush
    )
    export class MyComponent implements OnInit
    constructor(private _cdRef: ChangeDetectorRef)


    ngOnInit(): void
    fromEvent(window, 'resize') // get the event observable
    .pipe(debounceTime(200)) // you can change debounceTime to whatever you want
    .subscribe((event) =>
    this._cdRef.markForCheck(); // Here we go
    );




    As the chart itself seems to be responsive and should be redrawn each window change, this will do the trick.






    share|improve this answer



























      0














      If you got component with changeDetection: ChangeDetectionStrategy.OnPush (which is a good idea to improve performance) then the good solution is to get markForCheck() fired each time you resize the window, but with debounceTime so you will get some time to wait before you resize the chart:



      import ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit from '@angular/core';
      import fromEvent from 'rxjs';
      import debounceTime from 'rxjs/operators';

      @Component(
      selector: 'my-component',
      templateUrl: 'my-component.html',
      styleUrls: ['./my-component.scss'],
      changeDetection: ChangeDetectionStrategy.OnPush
      )
      export class MyComponent implements OnInit
      constructor(private _cdRef: ChangeDetectorRef)


      ngOnInit(): void
      fromEvent(window, 'resize') // get the event observable
      .pipe(debounceTime(200)) // you can change debounceTime to whatever you want
      .subscribe((event) =>
      this._cdRef.markForCheck(); // Here we go
      );




      As the chart itself seems to be responsive and should be redrawn each window change, this will do the trick.






      share|improve this answer

























        0












        0








        0







        If you got component with changeDetection: ChangeDetectionStrategy.OnPush (which is a good idea to improve performance) then the good solution is to get markForCheck() fired each time you resize the window, but with debounceTime so you will get some time to wait before you resize the chart:



        import ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit from '@angular/core';
        import fromEvent from 'rxjs';
        import debounceTime from 'rxjs/operators';

        @Component(
        selector: 'my-component',
        templateUrl: 'my-component.html',
        styleUrls: ['./my-component.scss'],
        changeDetection: ChangeDetectionStrategy.OnPush
        )
        export class MyComponent implements OnInit
        constructor(private _cdRef: ChangeDetectorRef)


        ngOnInit(): void
        fromEvent(window, 'resize') // get the event observable
        .pipe(debounceTime(200)) // you can change debounceTime to whatever you want
        .subscribe((event) =>
        this._cdRef.markForCheck(); // Here we go
        );




        As the chart itself seems to be responsive and should be redrawn each window change, this will do the trick.






        share|improve this answer













        If you got component with changeDetection: ChangeDetectionStrategy.OnPush (which is a good idea to improve performance) then the good solution is to get markForCheck() fired each time you resize the window, but with debounceTime so you will get some time to wait before you resize the chart:



        import ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit from '@angular/core';
        import fromEvent from 'rxjs';
        import debounceTime from 'rxjs/operators';

        @Component(
        selector: 'my-component',
        templateUrl: 'my-component.html',
        styleUrls: ['./my-component.scss'],
        changeDetection: ChangeDetectionStrategy.OnPush
        )
        export class MyComponent implements OnInit
        constructor(private _cdRef: ChangeDetectorRef)


        ngOnInit(): void
        fromEvent(window, 'resize') // get the event observable
        .pipe(debounceTime(200)) // you can change debounceTime to whatever you want
        .subscribe((event) =>
        this._cdRef.markForCheck(); // Here we go
        );




        As the chart itself seems to be responsive and should be redrawn each window change, this will do the trick.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 12:44









        Al-MothafarAl-Mothafar

        4,04534674




        4,04534674



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300539%2fkendo-ui-for-angular-pie-charts-is-not-responsive-with-changedetectionstrategy-o%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            ReactJS Fetched API data displays live - need Data displayed static

            Evgeni Malkin