ngx-charts单击点,打开用户输入,在注释中显示用户输入

时间:2017-10-23 07:40:04

标签: angular ngx-charts

我使用ngx-charts折线图来显示每周的访问者。我使用模拟数据在图表中创建点。我想要达到的目的是用户可以输入类似“平安夜”的内容。当他/她点击某个点然后在该点显示注释时。我不知道如何在ngx-charts中做到这一点。

当前代码:

import { Component, OnInit } from '@angular/core';
import {NgxChartsModule} from '@swimlane/ngx-charts';

@Component({
  selector: 'app-ngx-charts',
  templateUrl: './ngx-charts.component.html',
  styleUrls: ['./ngx-charts.component.css'],
  template: `
    <mat-card>
      <ngx-charts-line-chart
      [options]="options" (load)="saveInstance($event.context)">
      [view]="view"
      [scheme]="colorScheme"
      [results]="multi"
      [gradient]="gradient"
      [xAxis]="showXAxis"
      [yAxis]="showYAxis"
      [legend]="showLegend"
      [showXAxisLabel]="showXAxisLabel"
      [showYAxisLabel]="showYAxisLabel"
      [xAxisLabel]="xAxisLabel"
      [yAxisLabel]="yAxisLabel"
      [autoScale]="autoScale"
      (select)="onSelect($event)">
      </ngx-charts-line-chart>
    </mat-card>
   `
})
export class NgxChartsComponent implements OnInit {
  single: any[] = [ {
    "name": "Germany",
    "value": 8940000
  }];

  multi: any[] = [
    {
      "name": "Germany",
      "series": [
        {
          "value": 4029,
          "name": "2016-09-21T14:30:06.482Z"
        },
        {
          "value": 4550,
          "name": "2016-09-20T17:52:47.417Z"
        },
        {
          "value": 3449,
          "name": "2016-09-23T19:03:19.247Z"
        },
        {
          "value": 4641,
          "name": "2016-09-19T19:21:40.329Z"
        },
        {
          "value": 5141,
          "name": "2016-09-16T09:58:23.402Z"
        }
      ]
    }
  ];

  view: any[] = [700, 400];

  // options
  showXAxis = true;
  showYAxis = true;
  gradient = false;
  showLegend = true;
  showXAxisLabel = true;
  xAxisLabel = 'Country';
  showYAxisLabel = true;
  yAxisLabel = 'Population';

  colorScheme = {
    domain: ['#5AA454', '#A10A28', '#C7B42C', '#AAAAAA']
  };

  // line, area
  autoScale = true;

  onSelect(event) {
    console.log(event + "Banaan!");

  }

  ngOnInit() {
  }

}

0 个答案:

没有答案