1

我正在Object从我的数据库中导入日期。不幸的是,日期显示为Unix时间戳(-62101391858000)。我知道可以pipes像这样格式化我的日期:{{myDate | date:medium}}但我正在使用ng2-charts,因此我必须以另一种方式解决这个问题。我的图表显示如下:

<base-chart class="chart" 
    [datasets]="lineData" 
    [labels]="lineLabels" 
    [options]="lineChartOptions" 
    [colors]="lineChartColours"
    [legend]="lineChartLegend" 
    [chartType]="lineChartType">
</base-chart>

我试图找到<base-chart>,但它隐藏在ng2-charts魔法的某个地方。

关于如何解决这个问题的任何建议?

4

2 回答 2

0

我现在想通了,而不是尝试pipe在前端输出,我只是做了一个typecast

this.temp1.push(new Date(data[i]["truncStartTime"]).toLocaleDateString());

代替:

this.temp1.push(data[i]["truncStartTime"]);
于 2016-08-03T07:09:01.413 回答
0

您只需声明时间为 UNIX 时间(Moments.js - 标记“X”)。

  scales: {
  xAxes: [{

              type: 'time',
              time: {
                    format: 'X',
                    displayFormats: {minute: 'HH:mm'},
                                         // round: 'day'
                                  tooltipFormat: 'll HH:mm'
                  },

重要的部分是'格式:'X'

于 2016-10-16T07:55:53.783 回答