使用角度服务时,ng2-charts不会重绘

时间:2018-03-14 11:45:20

标签: angular ng2-charts

我尝试使用角度服务来重绘ng2图表。 在本地使用图形组件时,图形获取重绘。

当我尝试使用角度共享服务时,图表不会重绘

谁知道我做错了什么?

本教程完成了服务注入: 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();

  }


}

0 个答案:

没有答案