2017-02-27 2 views
0

나는이 문제가 거의 없다고 생각한다. 차트에 점을 추가하려고하면 데이터의 값을 추가하지만 점은 추가하지 않습니다. 아이디어가 있으십니까?각도 io highchart 소켓 io

모듈 ==>

import { Component } from '@angular/core'; 
import * as io from 'socket.io-client'; 
@Component({ 
    selector: 'app-root', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'], 

}) 

export class AppComponent{ 
    url = 'http://localhost:5000'; 
    socket : any; 
    chart : any; 
    options: any; 
    v:any; 
    constructor() { 
    this.socket = io.connect(this.url); 
    this.options = { 
     title: { text : 'chart with dynamic data' }, 
     series: [{ 
      data: [2,3,5,8] 
     }] 
    } 
    this.getMessages(); 
} 

saveInstance(chartInstance) { 
    this.chart = chartInstance.context; 
} 
addPoint(n:any) { 
    this.chart.series[0].addPoint(n); 
} 
sendMessage(n:any){ 

    this.socket.emit('add-message',n);  
} 
getMessages() { 
    this.socket.on('message', (data) => { 
     console.log(data) 
     this.addPoint(data); 
    }) 
} 

}

HTML ==>

<chart [options]="options" (load)="saveInstance($event)"></chart> 
<input #v (keyup.enter)="sendMessage(v.value)"> 
+1

귀하의 코드가 완료되지 않은 morganfree 적합한 솔루션 들으이었다 문제를 재현 할 수 없습니다. 이 동작은 number 대신 string/undefined를 점으로 추가하면 발생합니다. addPoint() 메서드를 사용하기 전에 문자열을 숫자로 변환했는지/null을 보내지 않았는지 확인하십시오. – morganfree

+0

Perfect! ParseInt()는 그렇게 간단한 솔루션이었습니다 ... – Nod

답변

1

에서는 parseInt()는 당신이