Angular 角4中带有子记录方法的饼图

Angular 角4中带有子记录方法的饼图,angular,typescript,rxjs,angular2-highcharts,Angular,Typescript,Rxjs,Angular2 Highcharts,有一个非常小的问题,但我不明白,我正在尝试使用angular2 highchart、rxjs和Angular 4在我的饼图中从Json中注入操作速率值。这是我的代码,我认为这是一个格式问题,因为当我使用操作速率细节时,它完成了工作: pieChart.ts: import { Component, OnInit, Input, OnDestroy } from '@angular/core'; import { UserService3 } from '../user3.service'; im

有一个非常小的问题,但我不明白,我正在尝试使用angular2 highchart、rxjs和Angular 4在我的饼图中从Json中注入操作速率值。这是我的代码,我认为这是一个格式问题,因为当我使用操作速率细节时,它完成了工作:

pieChart.ts:

import { Component, OnInit, Input, OnDestroy } from '@angular/core';
import { UserService3 } from '../user3.service';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';

@Component({
  selector: 'my-daydetail',
  templateUrl: './my-daydetail.component.html',
  styleUrls: ['./my-daydetail.component.css']
})
export class MyDaydetailComponent implements OnDestroy, OnInit {



// Içi je crée un un import depuis le composent appliV2.html
    @Input() showMePartially: boolean;



    options: any;
    data: Object[];
    chart: any;
// Ici j'importe la variable Subscription de l'api Rxjs que je stock dans une variable
    dataSubscription: Subscription;


     constructor(public userService3: UserService3) {

           this.options = {
            chart: {  type: 'pie',
                 plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false,  },
   //     legend: { enabled: false },
        credits: { enabled: false },
         tooltip: {
  //     pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
   },
   plotOptions: {
    pie: {
        allowPointSelect: false,
        cursor: 'pointer',
        dataLabels: {
            enabled: false,
     //      format: '<b>{point.name}</b>: {point.percentage:.1f} %',
        }
      }
    },


        series: [{
          name: 'Dispo',
          data: []
        }]
       };
   }



   saveInstance(chartInstance) {
    this.chart = chartInstance;
 //   console.log(chartInstance);
}

   public ngOnInit () {
    this.dataSubscription = 
this.userService3.getData().subscribe((data) => {
      this.options.series[0].data = data.data.operating_rate;
     console.log(data);
   });
}
    public ngOnDestroy() {
      if (this.dataSubscription){
this.dataSubscription.unsubscribe();
}
}
}
pieChart.html:

我的Json的一部分: {状态:正常,数据: {运行率:88.14,运行持续时间:20h02mn, 不工作的杜拉蒂 on:2h40mn,操作详细信息:[[1497837618,0],[14978377338,0], [1497837858,0],[1497837978,0],[1497838098,0],[1497838218,0], [1497838338,0],[1497838458,0],[1497838578,0],[1497838698,0], [1497838818,0],[1497838938,0],[1497839058,0],[1497839178,0], [1497839298,0],[1497839418,0],[1497839538,0],[1497839658,0], [1497839778,0],[1497839898,0],[1497840018,0]]

这是我的服务。ts:

   getData() {

     const tick3$ = Observable.timer(100, 60000);

     return tick3$.flatMap(() => this.http.get(usersURL)).map(res => 
res.json());   // .publishBehavior(<User3[]>[]).refCount();



 } 

我相信你想要的是类似于

// series data of your highcharts options
this.options.series[0].data = [
    {
        name: 'Operating Duration',
        y: data.data.operating_rate // this is the response from your json call
    },
    {
        name: 'Non-Operating Duration',
        y: 100 - data.data.operating_rate
    }
];

根据highcharts文档

你有什么问题/问题?@Raven我的问题是如何在我的图表中注入手术率88.14嘿,我的朋友,你好吗?我在上次结束时成功了:所以现在只是一个馅饼,但y:100-res.data。手术率不起作用,它说我找不到“res”@EmileCantero我很好!可以吗你把你的代码贴到哪里去了?@EmileCantero我已经更新了我的答案,用数据代替了res。你在订阅回调中用数据代替了res。序列:[{name:'Dispo',data:[=>我应该把你的代码放在这里吗?]}]@EmileCantero正确!这将告诉highcharts在piechart中渲染什么
// series data of your highcharts options
this.options.series[0].data = [
    {
        name: 'Operating Duration',
        y: data.data.operating_rate // this is the response from your json call
    },
    {
        name: 'Non-Operating Duration',
        y: 100 - data.data.operating_rate
    }
];