[我想做的是使用setRsi()
函数创建数组,然后使用doOutput()
函数绘制数组,这将打开一个新对话框,用于使用ngg-charts
组件显示结果。
这是flow.component.ts
文件,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
您将必须放入所有变量
var mellat = Mellat;
var shepna = Shepna;
var macd_result = MACD_RESULT;
var rsi_result = RSI_RESULT;
在导出类块中而不使用如下所示的var关键字。
export class NgxChartsComponent implements OnInit {
mellat = Mellat;
shepna = Shepna;
macd_result = MACD_RESULT;
rsi_result = RSI_RESULT;
constructor(public dialogRef: MatDialogRef<NgxChartsComponent>) { }
}
因为使用var将创建一个全局变量,您将无法在“ this”对象中获得该变量