在Y轴上显示2个图表的日期范围

时间:2018-08-01 09:14:59

标签: javascript angular chart.js ng2-charts ngx-charts

我正在使用ng2图表以图表形式显示数据。我可以自定义X轴标签。但我想在Y轴上显示日期。当我传递日期作为输入时,它将以负数形式向我显示y轴值,并且图表将无法正常工作。日期将如1月1日至1月5日,1月6日至1月10日等。 预先谢谢你

public lineChartData: Array<any> = [
    { data: ['1 Jan to 5 Jan', '6 Jan to 10 Jan', '11 Jan to 15 Jan', '16 Jan to 20 Jan', '21 Jan to 25 Jan', '26 Jan to 30 Jan', '31 Jan to 4 Feb'], label: 'Series A'}
  ];
  public lineChartLabels: Array<any> = ['Module 1', 'Module 2', 'Module 3', 'Module 4', 'Module 5', 'Module 6', 'Module 7'];
  public lineChartOptions: any = {
    responsive: true
  };
  public lineChartColors: Array<any> = [
    { // grey
      backgroundColor: 'rgba(148,159,177,0.2)',
      borderColor: 'rgba(148,159,177,1)',
      pointBackgroundColor: 'rgba(148,159,177,1)',
      pointBorderColor: '#fff',
      pointHoverBackgroundColor: '#fff',
      pointHoverBorderColor: 'rgba(148,159,177,0.8)'
    },
    { // dark grey
      backgroundColor: 'rgba(77,83,96,0.2)',
      borderColor: 'rgba(77,83,96,1)',
      pointBackgroundColor: 'rgba(77,83,96,1)',
      pointBorderColor: '#fff',
      pointHoverBackgroundColor: '#fff',
      pointHoverBorderColor: 'rgba(77,83,96,1)'
    },
    { // grey
      backgroundColor: 'rgba(148,159,177,0.2)',
      borderColor: 'rgba(148,159,177,1)',
      pointBackgroundColor: 'rgba(148,159,177,1)',
      pointBorderColor: '#fff',
      pointHoverBackgroundColor: '#fff',
      pointHoverBorderColor: 'rgba(148,159,177,0.8)'
    }
  ];
  public lineChartLegend: boolean = true;
  public lineChartType: string = 'line';

  // events
  public chartClicked(e: any): void {
    console.log(e);
  }

  public chartHovered(e: any): void {
    console.log(e);
  }
<div class="col-md-12" style="display: block;">
            <canvas baseChart [datasets]="lineChartData" [labels]="lineChartLabels" [options]="lineChartOptions" [colors]="lineChartColors" [legend]="false" [chartType]="lineChartType" (chartHover)="chartHovered($event)" (chartClick)="chartClicked($event)"></canvas>
        </div>

0 个答案:

没有答案