如何获取Firebase时间戳

时间:2018-10-23 09:31:12

标签: angular firebase ionic-framework firebase-realtime-database chart.js

我想使用chart.js显示图表,但问题是我拥有大量数据,因此需要在x轴上按日期显示它。如何在Firebase中检索时间戳?还是可以用我自己的x轴来显示所有值,因为目前我只显示7个数据,因为我一个月只有7个。

enter image description here

  ionViewDidLoad() {
    this.afAuth.authState.take(1).subscribe(auth => {
    this.progress=this.afDatabase.list(`progress/${auth.uid}/${this.type}`,ref=>ref.orderByChild('date'))
    this.progress.valueChanges().subscribe(e=>{
      this.data = e;
      for(let d of this.data){
       this.s.push(d.score);
      }
      this.generateChart(this.s);
    })



  });
  }


  generateChart(data){
    this.lineChart = new Chart(this.lineCanvas.nativeElement, {
      type: 'line',
      data: {
         // WANT TO REPLACE VALUE HERE
          labels: ["January", "February", "March", "April", "May", "June", "July"], 
          datasets: [
              {
                  label: "My First dataset",
                  fill: false,
                  lineTension: 0.1,
                  backgroundColor: "rgba(75,192,192,0.4)",
                  borderColor: "rgba(75,192,192,1)",
                  borderCapStyle: 'butt',
                  borderDash: [],
                  borderDashOffset: 0.0,
                  borderJoinStyle: 'miter',
                  pointBorderColor: "rgba(75,192,192,1)",
                  pointBackgroundColor: "#fff",
                  pointBorderWidth: 1,
                  pointHoverRadius: 5,
                  pointHoverBackgroundColor: "rgba(75,192,192,1)",
                  pointHoverBorderColor: "rgba(220,220,220,1)",
                  pointHoverBorderWidth: 2,
                  pointRadius: 1,
                  pointHitRadius: 10,
                  data: data,
                  spanGaps: false,
              }
          ]
      }

  });
  }

0 个答案:

没有答案