Maximizing Angular Charts Performance with Lazy Loading
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (175).NET Core  (29).NET MAUI  (208)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (220)BoldSign  (15)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (67)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (101)Streamlit  (1)Succinctly series  (131)Syncfusion  (920)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (37)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (151)Chart  (132)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (633)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (41)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (508)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (11)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (597)What's new  (333)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Maximizing Angular Charts Performance with Lazy Loading

Maximizing Angular Charts Performance with Lazy Loading

The Syncfusion Angular Charts component is a powerful tool for visualizing and presenting data. While charts are a great way to display information, they can become sluggish and difficult to manage when dealing with extensive data sets. This is where the lazy loading features come into play.

Lazy loading displays data based on user-defined criteria, such as a specified range or the number of data points to be displayed, instead of loading all records simultaneously. Lazy loading ensures that only the data within the current range or point count is rendered in the Charts while scrolling.

This blog will explore how lazy loading features can significantly improve performance and enhance the user experience when working with substantial data in Angular Charts.

Note: If you’re new to our Angular Charts, we recommend going through its documentation before proceeding.

Getting started with lazy loading in Angular Charts

As we get started, our primary focus will be on understanding and implementing point length and range.

Using point length

With the point length concept in lazy loading, we can streamline the process of loading and displaying specific data segments from the data source on a chart. As users interact and scroll through the chart, the scrollEnd event is triggered, dynamically fetching and rendering the subsequent batch of data.

Let’s examine a practical example of this data-loading mechanism based on point length. In our initial load, we only loaded 200 data points out of the 1,000 available in the data source into the chart. As a result, only the initially loaded data will be visible to users. The scrollEnd event is activated as users scroll through, providing start and end values for the next data set. These values can be leveraged to load and populate the chart with pertinent data.

Refer to the following code example.

import { Component, OnInit } from '@angular/core';
import { lineData } from './datasource';
@Component({
    selector: 'app-container',
    template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis' (scrollEnd)='scrollEnd($event)'>
        <e-series-collection>
            <e-series [dataSource]='data' type='Line' xName='x' yName='y'></e-series>
        </e-series-collection>
    </ejs-chart>`
})
export class AppComponent implements OnInit {
    public chartData?: Object[];
    public primaryXAxis?: Object;
        public data: Object[] = this.GetNumericData(1, 200);
    ngOnInit(): void {
        this.chartData = lineData;
        this.primaryXAxis = {
            scrollbarSettings: { pointsLength: 1000 }
        };
    }
    public scrollEnd(args: IScrollEventArgs): void {
         //Assigning the next set of data to the chart based on the minimum and maximum values. 
          this.chart.series[0].dataSource = this.GetNumericData(args.currentRange.minimum as number,  args.currentRange.maximum as number);
        this.chart.dataBind();
    };
}

public GetNumericData(start: number, end: number): { x: number, y: number }[] {
        let series: { x: number, y: number }[] = [];
        let value: number = 30;
        for (let i: number = start; i <= end; i++) {
            if (Math.random() > .5) {
                value += (Math.random() * 10 - 5);
            } else {
                value -= (Math.random() * 10 - 5);
            }
            if (value < 0) {
                value = this.getRandomInt(20, 40);
            }
            let point: { x: number, y: number } = { x: i, y: Math.round(value) };
            series.push(point);
        }
        return series;
}

Refer to the following output image.

Lazy loading data in Angular Charts using point length concept
Lazy loading data in Angular Charts using point length concept

Using range

We can load and display a specific data range from the data source in a chart with the range concept in lazy loading. The scrollEnd event is triggered as users scroll, which dynamically loads and presents the subsequent data range.

For instance, in the following code example, we initially loaded data from January 1, 2009, to September 1, 2009. Consequently, only the data falling within this specified range will be visible. As users scroll, the ScrollEnd event will be triggered, providing the range for the next set of data. You can use these range values to load and populate the chart with the relevant data.

Refer to the following code example.

import { Component, OnInit } from '@angular/core';
import { lineData } from './datasource';
@Component({
    selector: 'app-container',
    template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis' (scrollEnd)='scrollEnd($event)'>
        <e-series-collection>
         <e-series [dataSource]='chartData' type='Line' xName='x' yName='y'></e-series>
        </e-series-collection>
    </ejs-chart>`
})
export class AppComponent implements OnInit {
    public chartData?: Object[];
    public primaryXAxis?: Object;
    public data: Object[] = this.GetDateTimeData(new Date(2009, 0, 1), new Date(2009, 8, 1));
    ngOnInit(): void {
        this.chartData = lineData;
        this.primaryXAxis = {
            scrollbarSettings: {    
                 range: {
                     minimum: new Date(2009, 0, 1),
                     maximum: new Date(2014, 0, 1)
                 },
            }
        };
    }
   public scrollEnd(args: IScrollEventArgs): void {
        //Assigning next set of data to the chart based on the new range. 
         this.chart.series[0].dataSource = this.GetDateTimeData(args.currentRange.minimum as Date, args.currentRange.maximum as Date);        
        this.chart.dataBind();
   };
}

public GetDateTimeData(start: Date, end: Date): { x: Date, y: number }[] {
        let series: { x: Date, y: number }[] = [];
        let date: number;
        let value: number = 30;
        let option: DateFormatOptions = {
            skeleton: 'full',
            type: 'dateTime'
        };
        let dateParser: Function = this.intl.getDateParser(option);
        let dateFormatter: Function = this.intl.getDateFormat(option);
        for (let i: number = 0; start <= end; i++) {
            date = Date.parse(dateParser(dateFormatter(start)));
            if (Math.random() > .5) {
                value += (Math.random() * 10 - 5);
            } else {
                value -= (Math.random() * 10 - 5);
            }
            if (value < 0) {
                value = this.getRandomInt(20, 40);
            }
            let point: { x: Date, y: number } = { x: new Date(date), y: Math.round(value) };
            new Date(start.setDate(start.getDate() + 1));
            series.push(point);
        
        return series;
}

Refer to the following output image.

Lazy loading data in Angular Charts using range concept
Lazy loading data in Angular Charts using range concept

References

For more details, refer to the lazy loading in the Angular Charts demo and documentation.

Conclusion

Thanks for reading! In this blog, we’ve seen how the lazy-loading feature helps us enhance performance and the user experience in the Angular Charts component. We appreciate your feedback, which you can leave in the comments section below.

You can download our free trial if you do not have a Syncfusion license but wish to try the Charts component.

For questions, you can contact us via our support forumssupport portal, or feedback portal. We are always happy to assist you!

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed