Can you generate sine wave data continuously from an Angular service and inject it into a component?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Can you generate sine wave data continuously from an Angular service and inject it into a component?



I have a component which has an injected service to retrieve static mock data. I would like to add the ability to generate data at a variable frequency and send the new (appended, time series) data to the component as it is generated.



I can't for the life of me figure out how to accomplish this.



All I know for sure is that the data object for the component must be immutable.



plotter.component.ts:


import { Component, OnInit } from '@angular/core';

import { MockDataService } from '../../services/mock-data/mock-data.service';

@Component({
selector: 'app-plotter',
templateUrl: './plotter.component.html',
styleUrls: ['./plotter.component.css']
})
export class PlotterComponent implements OnInit {

single: any;
multi: any;

// rt needs to be an immutable object array
// rt needs to be updated with data from MockDataService
rt: any;

view: any = [700, 400];

// options
showXAxis = true;
showYAxis = true;
gradient = false;
showLegend = true;
showXAxisLabel = true;
xAxisLabel = 'Country';
showYAxisLabel = true;
yAxisLabel = 'Population';

colorScheme = {
domain: ['#5AA454', '#A10A28', '#C7B42C', '#AAAAAA']
};

// line, area
autoScale = true;

constructor(private mockDataService: MockDataService) {
// Object.assign(this, { single, multi });
this.single = mockDataService.getSingle();
this.multi = mockDataService.getMulti();
}

ngOnInit() {

}

onSelect(event) {
console.log(event);
}

}



mock-data.service.ts


import { Injectable } from '@angular/core';
import { single, multi } from '../../mock-data/plot-data';

@Injectable({
providedIn: 'root'
})
export class MockDataService {

constructor() { }

getSingle() {
return single;
}

getMulti() {
return multi;
}

// Generate sine wave data here
sineWave(pAmplitude, pFrequency) {

}

}









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results