简体   繁体   English

如何 plot 折线图有多个数据,但只有 2 个标签?

[英]How to plot line chart with multiple datas, but only 2 labels?

So,所以,

I've been using ng2-charts to so I can create components using the chartjs library in my angular application and I want to plot a chart that shows only the first and last label and point so the chart can be easy to read and clean.我一直在使用 ng2-charts,因此我可以在我的 angular 应用程序中使用 chartjs 库创建组件,并且我想要 plot 一个仅显示第一个和最后一个 ZD304BA20E96D874341588EE 图表的图表和干净的点。

How can I just show the first and last one?我怎样才能显示第一个和最后一个?

Or only the last one或者只有最后一个

In Chart.js the labels can be provided as an array.在 Chart.js 中,标签可以作为数组提供。

Example例子

component.html组件.html

<canvas baseChart width="400" height="400"
                    [datasets]="lineChartData"
                    [labels]="lineChartLabels"
                    chartType="line"></canvas>

component.ts组件.ts

  public lineChartData: ChartDataSets[] = [
    { data: [65, 59, 80, 81, 56, 55, 40], label: 'Series A' }
  ];
  public lineChartLabels: Label[] = ['January', '', '', '', '', '', 'July'];

As per your requirement, you can set empty values for labels except first and last one.根据您的要求,您可以为标签设置空值,第一个和最后一个除外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM