highcharts-angular dynamically update from DB











up vote
0
down vote

favorite












I'm using highcharts-angular in angular 6 app.
When I set data, hardcore it, in ngOnInit, chart is visible and works correctly.



But I want to update chart series dynamically, meaning add point to the series, add new series...
This will be done after calling web API and getting new data, calling loadBidChartData().



If I set new series for chat, or update series, chart don't see changes, initial state is not changing.
How can I solve this?



Here is small peace of example code
in html is like this:



<highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [update]="true" ></highcharts-chart> 


in angular:



 import * as Highcharts from 'highcharts';
export class ExampleComponent implements OnInit {
Highcharts = Highcharts; // required
chartOptions = {
chart: {
type: "scatter",
width: 900
},
},
tooltip: {
valueDecimals: 0,
formatter: function () {
return this.y + ' €';
}
},
title: {
text: ''
},
xAxis: {
type: 'datetime',
},
yAxis: {
type: 'number',
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
floating: false,
borderWidth: 1
},
series:
};

ngOnInit(): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
}];
}

loadBidChartData(bidApiModel: BidItem): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
},
{
name: 'second last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
}];
}
}


Solution:
Working demo with updating in background and adding and removing points to highcharts: https://stackblitz.com/edit/angular-bv26xz

Thank you User3250 and Wojciech Chmiel for the help.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I'm using highcharts-angular in angular 6 app.
    When I set data, hardcore it, in ngOnInit, chart is visible and works correctly.



    But I want to update chart series dynamically, meaning add point to the series, add new series...
    This will be done after calling web API and getting new data, calling loadBidChartData().



    If I set new series for chat, or update series, chart don't see changes, initial state is not changing.
    How can I solve this?



    Here is small peace of example code
    in html is like this:



    <highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [update]="true" ></highcharts-chart> 


    in angular:



     import * as Highcharts from 'highcharts';
    export class ExampleComponent implements OnInit {
    Highcharts = Highcharts; // required
    chartOptions = {
    chart: {
    type: "scatter",
    width: 900
    },
    },
    tooltip: {
    valueDecimals: 0,
    formatter: function () {
    return this.y + ' €';
    }
    },
    title: {
    text: ''
    },
    xAxis: {
    type: 'datetime',
    },
    yAxis: {
    type: 'number',
    },
    legend: {
    layout: 'vertical',
    align: 'right',
    verticalAlign: 'top',
    floating: false,
    borderWidth: 1
    },
    series:
    };

    ngOnInit(): void {
    this.chartOptions.series= [{
    name: 'first last',
    data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
    }];
    }

    loadBidChartData(bidApiModel: BidItem): void {
    this.chartOptions.series= [{
    name: 'first last',
    data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
    },
    {
    name: 'second last',
    data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
    }];
    }
    }


    Solution:
    Working demo with updating in background and adding and removing points to highcharts: https://stackblitz.com/edit/angular-bv26xz

    Thank you User3250 and Wojciech Chmiel for the help.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm using highcharts-angular in angular 6 app.
      When I set data, hardcore it, in ngOnInit, chart is visible and works correctly.



      But I want to update chart series dynamically, meaning add point to the series, add new series...
      This will be done after calling web API and getting new data, calling loadBidChartData().



      If I set new series for chat, or update series, chart don't see changes, initial state is not changing.
      How can I solve this?



      Here is small peace of example code
      in html is like this:



      <highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [update]="true" ></highcharts-chart> 


      in angular:



       import * as Highcharts from 'highcharts';
      export class ExampleComponent implements OnInit {
      Highcharts = Highcharts; // required
      chartOptions = {
      chart: {
      type: "scatter",
      width: 900
      },
      },
      tooltip: {
      valueDecimals: 0,
      formatter: function () {
      return this.y + ' €';
      }
      },
      title: {
      text: ''
      },
      xAxis: {
      type: 'datetime',
      },
      yAxis: {
      type: 'number',
      },
      legend: {
      layout: 'vertical',
      align: 'right',
      verticalAlign: 'top',
      floating: false,
      borderWidth: 1
      },
      series:
      };

      ngOnInit(): void {
      this.chartOptions.series= [{
      name: 'first last',
      data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
      }];
      }

      loadBidChartData(bidApiModel: BidItem): void {
      this.chartOptions.series= [{
      name: 'first last',
      data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
      },
      {
      name: 'second last',
      data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
      }];
      }
      }


      Solution:
      Working demo with updating in background and adding and removing points to highcharts: https://stackblitz.com/edit/angular-bv26xz

      Thank you User3250 and Wojciech Chmiel for the help.










      share|improve this question















      I'm using highcharts-angular in angular 6 app.
      When I set data, hardcore it, in ngOnInit, chart is visible and works correctly.



      But I want to update chart series dynamically, meaning add point to the series, add new series...
      This will be done after calling web API and getting new data, calling loadBidChartData().



      If I set new series for chat, or update series, chart don't see changes, initial state is not changing.
      How can I solve this?



      Here is small peace of example code
      in html is like this:



      <highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [update]="true" ></highcharts-chart> 


      in angular:



       import * as Highcharts from 'highcharts';
      export class ExampleComponent implements OnInit {
      Highcharts = Highcharts; // required
      chartOptions = {
      chart: {
      type: "scatter",
      width: 900
      },
      },
      tooltip: {
      valueDecimals: 0,
      formatter: function () {
      return this.y + ' €';
      }
      },
      title: {
      text: ''
      },
      xAxis: {
      type: 'datetime',
      },
      yAxis: {
      type: 'number',
      },
      legend: {
      layout: 'vertical',
      align: 'right',
      verticalAlign: 'top',
      floating: false,
      borderWidth: 1
      },
      series:
      };

      ngOnInit(): void {
      this.chartOptions.series= [{
      name: 'first last',
      data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
      }];
      }

      loadBidChartData(bidApiModel: BidItem): void {
      this.chartOptions.series= [{
      name: 'first last',
      data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
      },
      {
      name: 'second last',
      data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
      }];
      }
      }


      Solution:
      Working demo with updating in background and adding and removing points to highcharts: https://stackblitz.com/edit/angular-bv26xz

      Thank you User3250 and Wojciech Chmiel for the help.







      angular highcharts






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 9:29

























      asked Nov 19 at 12:39









      user1698635

      358




      358
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You need to use [(update)] flag to update the series as below:



          loadBidChartData(bidApiModel: BidItem): void {
          this.chartOptions.series= [{
          name: 'first last',
          data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
          },
          {
          name: 'second last',
          data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
          }];
          this.updateFlag = true;
          }

          <highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [(update)]="updateFlag" ></highcharts-chart>


          Working demo here: https://stackblitz.com/edit/angular-d5spve






          share|improve this answer

















          • 2




            Check also this demo with an update: codesandbox.io/s/543l0p0qq4
            – Wojciech Chmiel
            Nov 20 at 7:17






          • 1




            Thank you for the demo with update Wojciech Chmiel
            – user1698635
            Nov 20 at 7:27











          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',
          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%2f53374858%2fhighcharts-angular-dynamically-update-from-db%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








          up vote
          1
          down vote



          accepted










          You need to use [(update)] flag to update the series as below:



          loadBidChartData(bidApiModel: BidItem): void {
          this.chartOptions.series= [{
          name: 'first last',
          data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
          },
          {
          name: 'second last',
          data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
          }];
          this.updateFlag = true;
          }

          <highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [(update)]="updateFlag" ></highcharts-chart>


          Working demo here: https://stackblitz.com/edit/angular-d5spve






          share|improve this answer

















          • 2




            Check also this demo with an update: codesandbox.io/s/543l0p0qq4
            – Wojciech Chmiel
            Nov 20 at 7:17






          • 1




            Thank you for the demo with update Wojciech Chmiel
            – user1698635
            Nov 20 at 7:27















          up vote
          1
          down vote



          accepted










          You need to use [(update)] flag to update the series as below:



          loadBidChartData(bidApiModel: BidItem): void {
          this.chartOptions.series= [{
          name: 'first last',
          data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
          },
          {
          name: 'second last',
          data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
          }];
          this.updateFlag = true;
          }

          <highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [(update)]="updateFlag" ></highcharts-chart>


          Working demo here: https://stackblitz.com/edit/angular-d5spve






          share|improve this answer

















          • 2




            Check also this demo with an update: codesandbox.io/s/543l0p0qq4
            – Wojciech Chmiel
            Nov 20 at 7:17






          • 1




            Thank you for the demo with update Wojciech Chmiel
            – user1698635
            Nov 20 at 7:27













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          You need to use [(update)] flag to update the series as below:



          loadBidChartData(bidApiModel: BidItem): void {
          this.chartOptions.series= [{
          name: 'first last',
          data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
          },
          {
          name: 'second last',
          data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
          }];
          this.updateFlag = true;
          }

          <highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [(update)]="updateFlag" ></highcharts-chart>


          Working demo here: https://stackblitz.com/edit/angular-d5spve






          share|improve this answer












          You need to use [(update)] flag to update the series as below:



          loadBidChartData(bidApiModel: BidItem): void {
          this.chartOptions.series= [{
          name: 'first last',
          data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
          },
          {
          name: 'second last',
          data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
          }];
          this.updateFlag = true;
          }

          <highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [(update)]="updateFlag" ></highcharts-chart>


          Working demo here: https://stackblitz.com/edit/angular-d5spve







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 at 14:46









          User3250

          1,5533825




          1,5533825








          • 2




            Check also this demo with an update: codesandbox.io/s/543l0p0qq4
            – Wojciech Chmiel
            Nov 20 at 7:17






          • 1




            Thank you for the demo with update Wojciech Chmiel
            – user1698635
            Nov 20 at 7:27














          • 2




            Check also this demo with an update: codesandbox.io/s/543l0p0qq4
            – Wojciech Chmiel
            Nov 20 at 7:17






          • 1




            Thank you for the demo with update Wojciech Chmiel
            – user1698635
            Nov 20 at 7:27








          2




          2




          Check also this demo with an update: codesandbox.io/s/543l0p0qq4
          – Wojciech Chmiel
          Nov 20 at 7:17




          Check also this demo with an update: codesandbox.io/s/543l0p0qq4
          – Wojciech Chmiel
          Nov 20 at 7:17




          1




          1




          Thank you for the demo with update Wojciech Chmiel
          – user1698635
          Nov 20 at 7:27




          Thank you for the demo with update Wojciech Chmiel
          – user1698635
          Nov 20 at 7:27


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53374858%2fhighcharts-angular-dynamically-update-from-db%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

          If I really need a card on my start hand, how many mulligans make sense? [duplicate]

          Alcedinidae

          Can an atomic nucleus contain both particles and antiparticles? [duplicate]