数据绑定中的问题-Kendo图表

问题描述 投票:0回答:1

我想显示一个图表(饼图/甜甜圈),显示一个人的年度出勤数据,为此我正在使用Kendo图表。我想在系列中显示“传奇中的年份”和“现在/不存在” /“不适用”。这是示例JSON数据源:[{"Year":"2018-2019","PresentDays":90,"AbsentDays":3,"NA":7},{"Year":"2019-2020","PresentDays": 85,"AbsentDays":10,"NA":5}]

注:年份是动态的,可能因人而异,也可能因年份而异。

PS:到目前为止,我一直在尝试为我提供《传奇》中的系列字段。但我想自定义图例以显示年份。任何建议都是可以理解的。谢谢。

angularjs kendo-ui
1个回答
0
投票

您可以重塑数据以用于甜甜圈图

import { Component } from '@angular/core';
import { LegendLabelsContentArgs } from '@progress/kendo-angular-charts';
import { IntlService } from '@progress/kendo-angular-intl';

@Component({
    selector: 'my-app',
    template: `
      <kendo-chart>

        <kendo-chart-title text="Attendance"></kendo-chart-title>

        <kendo-chart-legend [visible]="false"></kendo-chart-legend>

        <kendo-chart-area background="none"></kendo-chart-area>

        <kendo-chart-tooltip>
          <ng-template kendoChartSeriesTooltipTemplate
              let-value="value" 
              let-category="category" 
              let-series="series"
          >
              {{ category }} ({{ series.name }}): {{ value }}%
          </ng-template>
        </kendo-chart-tooltip>

        <kendo-chart-series>
          <kendo-chart-series-item 
              *ngFor="let series of pie_model; let outermost = last;"
              type="donut" 
              [startAngle]="150"
              [name]="series.name" 
              [data]="series.data"
              field="value"
              categoryField="category">

            <kendo-chart-series-item-labels 
              *ngIf="outermost"
              position="outsideEnd" background="none"
              [content]="labelContent">
            </kendo-chart-series-item-labels>
          </kendo-chart-series-item>
        </kendo-chart-series>
      </kendo-chart>
    `
})
export class AppComponent {
    public attendance: any[] = [
        {"Year":"2018-2019","PresentDays":90,"AbsentDays":3,"NA":7},
        {"Year":"2019-2020","PresentDays":85,"AbsentDays":10,"NA":5}
    ];

    public pie_model: any [] = [];

    constructor(private intl: IntlService) {

        for (var index=0; index<this.attendance.length; index++) {
          var item = this.attendance[index];
          var model_item = { 
            name: item.Year, 
            data: [
              { category: "PresentDays", value: item.PresentDays },
              { category: "AbsentDays", value: item.AbsentDays },
              { category: "NA", value: item.NA }
            ]
          };
          this.pie_model.push(model_item);
        }

        console.log(this.pie_model);

        this.labelContent = this.labelContent.bind(this);
    }

    public labelContent(args: LegendLabelsContentArgs): string {
        return `${args.dataItem.category}
        (${this.intl.formatNumber(args.dataItem.value, 'n')})`;
    }
}

© www.soinside.com 2019 - 2024. All rights reserved.