我正在尝试使用角度服务来重绘ng2图表 . 在本地使用图形组件时,图形 getting 重绘 .

当我尝试使用角度共享服务图表 not redraw

谁知道我做错了什么?

服务注入完成本教程:https://angular.io/tutorial/toh-pt4

从这里取得图表的示例https://github.com/valor-software/ng2-charts/blob/development/demo/src/app/components/charts/line-chart-demo.ts

https://github.com/valor-software/ng2-charts/blob/development/demo/src/app/components/charts/line-chart-demo.html

我的代码

CitiesComponent:

export class CitiesComponent implements OnInit, OnChanges {

  constructor(private http: HttpClient, private globals: Globals, public graphService: GraphService) {}

HTML:

....
<button (click)="graphService.randomGraph()">CLICK</button>
....

GraphService:

import { Injectable } from '@angular/core';
import {PricesLineChartComponentComponent} from './prices-line-chart-component/prices-line-chart-component.component';

@Injectable()
export class GraphService {

  constructor(public pricesComponent: PricesLineChartComponentComponent) { }

  public randomGraph(){
      this.pricesComponent.randomize();

  }


}