Я хочу создать массив с помощью функции setRsi()
, затем построить его с помощью функции doOutput()
, который открывает новое диалоговое окно для отображения результата с использованием компонента ngg-charts
.
Это * Файл 1006 * и метод setRsi()
представляют собой функцию триггера события щелчка:
export class FlowComponent implements AfterViewInit {
setRsi(selectedValue){
console.log('The RSI period is:' , selectedValue);
periodd = selectedValue;
this.label2 = ' نام اندیکاتور: RSI';
this.label3 = ' دوره زمانی: ' + periodd + 'روزه';
rsi_result = rsi({period: periodd, values: pricess});
console.log('The RSI result is:' , rsi_result);
}
doOutput(){
this.dialog.open(NgxChartsComponent ) ; //, {width: '500px', height: '500px'});
}
}
export const RSI_RESULT = rsi_result;
export const MACD_RESULT = macd_result;
doOutput()
также является другой функцией события щелчка, которая вызывает сообщение об ошибке.
Я вижу rsi_result
или macd_result
в консоли, когда я нажимаю на соответствующие кнопки, но когда я хочу экспортировать и импортировать данные в файл ngx-chart.component.ts
для построения графика данных, я получаю следующую ошибку:
ngx-charts.component.ts
:
import { Component, OnInit } from '@angular/core';
import {MatDialog, MatDialogRef} from '@angular/material';
import {MACD_RESULT , RSI_RESULT} from '../flow/flow.component';
import {Mellat, Khodro, Shepna} from '../shared/stock_inf';
import { NewsComponent } from '../news/news.component';
var mellat = Mellat;
var khodro = Khodro;
var shepna = Shepna;
var macd_result = MACD_RESULT;
var rsi_result = RSI_RESULT;
console.log(rsi_result);
@Component({
selector: 'app-ngx-charts',
templateUrl: './ngx-charts.component.html',
styleUrls: ['./ngx-charts.component.scss']
})
export class NgxChartsComponent implements OnInit {
constructor(public dialogRef: MatDialogRef<NgxChartsComponent>) { }
// data goes here
public single = [
{
"name": " درصد سود",
"value": 69
},
{
"name": " درصد زیان",
"value": 31
},
];
// LENGTH = RSI_RESULT.length;
newArray = rsi_result.map((e, i) => ({
"name": (i + 1).toString(),
"value": e,
}));
newArray2 = mellat.map((e, i) => ({
"name": (i + 1).toString(),
"value": e,
}));
public multi = [
{
"name": "RSI",
"series": this.newArray
},
{
"name": "Mellat",
"series": this.newArray2
},
];
//{name: (i + 1).toString(), value: e.toString()}
view: any[] = [700, 400];
// options for the chart
showXAxis = true;
showYAxis = true;
gradient = false;
showLegend = true;
showXAxisLabel = true;
xAxisLabel = 'زمان';
showYAxisLabel = true;
yAxisLabel = 'قیمت';
timeline = true;
colorScheme = {
domain: ['#5AA454', '#A10A28', '#C7B42C', '#AAAAAA']
};
// line, area
autoScale = true;
//pie
showLabels = true;
explodeSlices = false;
doughnut = false;
ngOnInit() {
}
}
Это сообщение об ошибке:
main.js:5431 Uncaught ReferenceError: Cannot access 'RSI_RESULT' before initialization
at Module.RSI_RESULT (main.js:5431)
at Module../src/app/ngx-charts/ngx-charts.component.ts (ngx-charts.component.ts:13)
at __webpack_require__ (bootstrap:79)
at Module../src/app/flow/flow.component.ts (main.js:5440)
at __webpack_require__ (bootstrap:79)
at Module../src/app/app.module.ts (app.component.ts:8)
at __webpack_require__ (bootstrap:79)
at Module../src/main.ts (main.ts:1)
at __webpack_require__ (bootstrap:79)
at Object.0 (main.ts:13)
Я думаю, что есть проблема при передаче RSI_RESULT
и MACD_RESULT
, и я также получаю следующие предупреждения:
client:126 [WDS] Warnings while compiling.
warnings @ client:126
(anonymous) @ socket.js:47
sock.onmessage @ SockJSClient.js:58
EventTarget.dispatchEvent @ sockjs.js:170
(anonymous) @ sockjs.js:887
SockJS._transportMessage @ sockjs.js:885
EventEmitter.emit @ sockjs.js:86
WebSocketTransport.ws.onmessage @ sockjs.js:2961
wrapFn @ zone-evergreen.js:1191
invokeTask @ zone-evergreen.js:391
runTask @ zone-evergreen.js:168
invokeTask @ zone-evergreen.js:465
invokeTask @ zone-evergreen.js:1603
globalZoneAwareCallback @ zone-evergreen.js:1629
client:135 Circular dependency detected:
src\app\flow\flow.component.ts -> src\app\ngx-charts\ngx-charts.component.ts -> src\app\flow\flow.component.ts
warnings @ client:135
(anonymous) @ socket.js:47
sock.onmessage @ SockJSClient.js:58
EventTarget.dispatchEvent @ sockjs.js:170
(anonymous) @ sockjs.js:887
SockJS._transportMessage @ sockjs.js:885
EventEmitter.emit @ sockjs.js:86
WebSocketTransport.ws.onmessage @ sockjs.js:2961
wrapFn @ zone-evergreen.js:1191
invokeTask @ zone-evergreen.js:391
runTask @ zone-evergreen.js:168
invokeTask @ zone-evergreen.js:465
invokeTask @ zone-evergreen.js:1603
globalZoneAwareCallback @ zone-evergreen.js:1629
client:135 Circular dependency detected:
src\app\ngx-charts\ngx-charts.component.ts -> src\app\flow\flow.component.ts -> src\app\ngx-charts\ngx-charts.component.ts
РЕДАКТИРОВАТЬ:
Если я помещу свои переменные в моем классе, как показано ниже:
export class NgxChartsComponent implements OnInit {
mellat = Mellat;
khodro = Khodro;
shepna = Shepna;
macd_result = MACD_RESULT;
rsi_result = RSI_RESULT;
...
}
Я получу следующие новые ошибки :
ERROR TypeError: Cannot read property 'map' of undefined
at new NgxChartsComponent (ngx-charts.component.ts:45)
at createClass (core.js:27865)
at createDirectiveInstance (core.js:27685)
at createViewNodes (core.js:38315)
at createRootView (core.js:38187)
at callWithDebugContext (core.js:39716)
at Object.debugCreateRootView [as createRootView] (core.js:38953)
at ComponentFactory_.create (core.js:26827)
at ComponentFactoryBoundToModule.create (core.js:22791)
at ViewContainerRef_.createComponent (core.js:26983)
View_NgxChartsComponent_Host_0 @ NgxChartsComponent_Host.ngfactory.js? [sm]:1
proxyClass @ compiler.js:19436
logError @ core.js:39651
handleError @ core.js:9162
dispatchEvent @ core.js:25822
(anonymous) @ core.js:37030
(anonymous) @ platform-browser.js:1789
invokeTask @ zone-evergreen.js:391
onInvokeTask @ core.js:34182
invokeTask @ zone-evergreen.js:390
runTask @ zone-evergreen.js:168
invokeTask @ zone-evergreen.js:465
invokeTask @ zone-evergreen.js:1603
globalZoneAwareCallback @ zone-evergreen.js:1629
NgxChartsComponent_Host.ngfactory.js? [sm]:1 ERROR CONTEXT DebugContext_ {view: {…}, nodeIndex: 1, nodeDef: {…}, elDef: {…}, elView: {…}}