0

I want to push some live-data in an array, to show the data in the ngx-line-chart.
This is my Linechart-Component:

export class LinechartComponent implements OnInit {

  data = [
    {
      "name": "Test",
      "series": [
        {
          'nam': 'Point1',
          'value': '5'
        },
        {
          "nam": "Point2",
          "value": '15'
        }
      ]
    },
  ];



  constructor( private GEtDataService: DataService) { }

  ngOnInit() {
    this.GEtDataService.onMessage = (msg: string) => {
      this.data = [{name: 'test',  series: {  'nam': 'testing', 'value': msg}}];
    };
  };

  }

But this doesn't work.
Furthermore, did anyone know, if there is a solution to implement an own structure of the array with ngx-line-chart?

Steffn
  • 275
  • 1
  • 6
  • 21

1 Answers1

0

You should specify the index and push the value to the array as follows,

 this.GEtDataService.onMessage = (msg: string) => {
      this.data[0].series.push({ 'nam': 'testing', 'value': msg});
 };
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396