Angular 4

Angular 4 Line Chart Example – How to Use Line Chart in Angular 4?

Line Chart –
A line-chart is a chart which used to displays information as a series of data points and it is called straight line segments.

Stayed Informed - Angular4 Interview Q/A

Example for Line Chart –

LineChart.Component.ts –
import {Component} from '@angular/core';

export class LineChart {

   data: any;
   Message: any[];

    constructor() {
        this.data = {
            labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
            datasets: [
                {
                    label: '',
                    data: [62, 58, 80, 82, 57, 56, 40],
                    fill: false,
                    borderColor: '#4bc0c0'
                },
                {
                    label: '',
                    data: [29, 47, 42, 19, 84, 25, 90],
                    fill: false,
                    borderColor: '#565656'
                }
            ]
        }
    }

    selectChartData(event) {
        this.Message = [];
        this.Message.push({ severity: 'info', summary: 'Your Data Selected', 'detail': this.data.datasets[event.element._datasetIndex].data[event.element._index] });
    }
}

Linechart.html –

<div class="row">
    <div class="col-lg-12" id="LineChart">
        <p-growl [value]="Message"></p-growl>
        <p-chart type="line" [data]="data" (onDataSelect)="selectChartData($event)"></p-chart>
    </div>
</div>

Result –
I hope you are enjoying with this post! Please share with you friends!! Thank you!!!
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.
^