2017-10-19 3 views
0

데이터는 반환되지만 차트 작성자 시리즈에서는로드되지 않지만 APIi 호출을 통해 차트 작성기 데이터를로드하려고합니다. 당신이 약속 resolved.Since getSeriesData, 당신은이 같은 somehting을해야 비동기되기 전에 차트 데이터 구축을 위해 노력하고 있습니다http get (각도 4)의 데이터로 Chartist를 채울 수 없습니다.

// Initialize data series 
seriesData: any[] = []; 

// Function to retrieve data from api 
getSeriesData() { 
    this.uid.getSeriesData(this.auth.getCurrentUser()).then(
     data => this.seriesData = data, // This is populated 
     err => console.log(err) 
    ); 
    } 

//ngInit 
ngOnInit() { 
    this.getSeriesData(); 

// Chartist 
const dataDailySalesChart: any = { 
     labels: ['M', 'T', 'W', 'T', 'F', 'S', 'S'], 
     series: [ 
     this.seriesData // THIS IS ALWAYS EMPTY 
     ] 
    }; 
} 
+0

, 당신이하기 전에 차트 데이터를 구축 그 약속은 아마도 해결되었을 것입니다. 당신이 그 데이터를 가지고 콜백 내부에 마십시오. – jonrsharpe

+0

@jonrsharpe, 제발 도와주세요. 나는 이것에 처음이에요. –

+0

[약속에서 데이터를 반환하는 방법] (https://stackoverflow.com/questions/37533929/how-to-return-data-from-promise) – jonrsharpe

답변

1

,

가 비어 물론
getSeriesData() { 
    this.uid.getSeriesData(this.auth.getCurrentUser()).then(
     data => this.seriesData = data, // This is populated 
     this.generateChart(this.seriesData), 
     err => console.log(err) 
    ); 
    } 

ngOnInit() { 
    this.getSeriesData();  
} 

generateChart(chartData:any){ 
     const dataDailySalesChart: any = { 
     labels: ['M', 'T', 'W', 'T', 'F', 'S', 'S'], 
     series: [ 
     chartData 
     ] 
    }; 
}; 
+0

신속한 답변을 보내 주셔서 감사합니다. 귀하의 예제가 작동하지만 여전히 generateChart 안에 있기 때문에 나는이 변수에 dataDailySalesChart를 전달할 수 없다. var dailySalesChart = new Chartist.Line ('# dailySalesChart', dataDailySalesChart, optionsDailySalesChart); –

+0

당신은 단지 데이터를 할당 할 수 있습니다 – Sajeetharan

+0

당신은 위대한 분입니다! 정말 고맙습니다. @jonrsharpe, 귀하의 기여에 감사드립니다. –

관련 문제