如何使用 ng2-chart 制作 Chart.js 气泡图?

How to make Chart.js Bubble chart with ng2-chart?

Chart.js supports bubble charts, but the ng2-chart 文档没有提到它们。 ng2-charts 可以制作气泡图吗?任何指向工作示例的指针都会很棒。

注:cross-posted on github

我看过 the source code。从版本 1.1.0(2016 年 5 月 17 日)开始,气泡图似乎不受支持。

npm 包 ng2-charts 现在支持气泡图(从版本 2.0.0-beta.10 开始)

这是演示应用程序的片段:

<div style="display: block">
  <canvas baseChart [datasets]="bubbleChartData" [options]="bubbleChartOptions" [colors]="bubbleChartColors"
    [legend]="bubbleChartLegend" [chartType]="bubbleChartType"></canvas>
</div>

代码:

import { Component, OnInit } from '@angular/core';
import { ChartOptions, ChartType, ChartDataSets } from 'chart.js';
import { Color } from 'ng2-charts';

@Component({
  selector: 'app-bubble-chart',
  templateUrl: './bubble-chart.component.html',
  styleUrls: ['./bubble-chart.component.scss']
})
export class BubbleChartComponent implements OnInit {
  public bubbleChartOptions: ChartOptions = {
    responsive: true,
    scales: {
      xAxes: [{ ticks: { min: 0, max: 30, } }],
      yAxes: [{ ticks: { min: 0, max: 30, } }]
    }
  };
  public bubbleChartType: ChartType = 'bubble';
  public bubbleChartLegend = true;

  public bubbleChartData: ChartDataSets[] = [
    {
      data: [
        { x: 10, y: 10, r: 10 },
        { x: 15, y: 5, r: 15 },
        { x: 26, y: 12, r: 23 },
        { x: 7, y: 8, r: 8 },
      ],
      label: 'Series A',
    },
  ];

  public bubbleChartColors: Color[] = [
    {
      backgroundColor: [
        'red',
        'green',
        'blue',
        'purple',
      ]
    }
  ];

  constructor() { }

  ngOnInit() {
  }
}

(我是那个包的合作者)。