LineChartA line chart or line graph is a type of chart which displays information as a series of data points called 'markers' connected by straight line segments.

Line - 图1

View on GitHub

  • linechartdemo.ts
  • linechartdemo.html

    linechartdemo.ts

  1. export class LineChartDemo {
  2. data: any;
  3. constructor(private messageService: MessageService) {
  4. this.data = {
  5. labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  6. datasets: [
  7. {
  8. label: 'First Dataset',
  9. data: [65, 59, 80, 81, 56, 55, 40],
  10. fill: false,
  11. borderColor: '#4bc0c0'
  12. },
  13. {
  14. label: 'Second Dataset',
  15. data: [28, 48, 40, 19, 86, 27, 90],
  16. fill: false,
  17. borderColor: '#565656'
  18. }
  19. ]
  20. }
  21. }
  22. selectData(event) {
  23. this.messageService.add({severity: 'info', summary: 'Data Selected', 'detail': this.data.datasets[event.element._datasetIndex].data[event.element._index]});
  24. }
  25. }
  26.  

linechartdemo.html

  1. <p-toast [style]="{marginTop: '80px'}"></p-toast>
  2. <p-chart type="line" [data]="data" (onDataSelect)="selectData($event)"></p-chart>
  3.