Try Upgrade Adviser – Scan Your Ext JS Codebase for V8 App Upgrade

Powerful Data Visualization Using JavaScript Carousels And NASA APIs

July 2, 2021 2822 Views

Get a summary of this article:

When it comes to presenting information visually, carousels are a great way to get the job done.  A carousel shows only one of its pages at a time but allows you to browse through multiple full-screen pages using a simple swipe gesture. You can think of a carousel as a single active item, with the rest of the items stretching away to the left and right. Indicator dots let the user know how many screens are available for them to swipe through.

In this blog post, we’ll look at how we can use NASA APIs to create beautiful JavaScript image carousels for powerful data visualization and analysis. This is one of our many extjs tutorial for beginners.

How can I get images from NASA APIs?

NASA provides a bunch of APIs that give you access to a variety of astronomical data. This data includes APOD, Asteroids NeoWs, DONKI, Earth, EONET, EPIC, and Exoplanet, to name a few. To use these APIs, you need to have an access token. You can create your access token by registering on the NASA portal with your email address and password.

For demonstration activities throughout this tutorial, we will use the following API calls to NASA to get the images for our Sencha carousel.

  • APOD (current day)
  • APOD (specific day)
  • Earth imagery

APOD API (current day)

let request = new XMLHttpRequest();
      request.open("GET", "https://api.nasa.gov/planetary/apod?api_key=<YOUR_API_KEY_HERE>");
       request.send();
       request.onload = () => {
         if (request.status === 200) {
           // by default the response comes in the string format, we need to parse the data into JSON
           console.log(JSON.parse(request.response));
         } else {
           console.log(`error ${request.status} ${request.statusText}`);
         }
       };

In the code above, we are calling NASA’s planetary APOD API with no optional query parameters. It means that it will return the astronomical picture of the day for the current day.

Notice that the api_key query parameter specifies a placeholder in the code snippet, You should replace this with your personal API access token before making the API call.

Earth Imagery API

let request = new XMLHttpRequest();       
request.open("GET", "https://api.nasa.gov/planetary/earth/imagery?lon=100.75&lat=1.5&date=2014-02-01&api_key=<YOUR_API_KEY_HERE>");
 request.send();
 request.onload = () => {
 if (request.status === 200) {
 // by default the response comes in the string format, we need to parse the data into JSON console.log(JSON.parse(request.response));
 } else {
 console.log(`error ${request.status} ${request.statusText}`);
 }
 };

Above, we are calling NASA’s earth imagery API with a series of query parameters. The API will return an earth image at the specified latitude and longitude values.

Notice that the api_key query parameter specifies a placeholder in the code snippet. Replace it with your personal API access token before making the API call.

APOD API (specific day)

let request = new XMLHttpRequest();
       request.open("GET", "https://api.nasa.gov/planetary/apod?date=2020-05-05&api_key=<YOUR_API_KEY_HERE>");
       request.send();
       request.onload = () => {
         if (request.status === 200) {
           // by default the response comes in the string format, we need to parse the data into JSON
           console.log(JSON.parse(request.response));
         } else {
           console.log(`error ${request.status} ${request.statusText}`);
         }
       };

 

Here, we are calling NASA’s planetary APOD API with the date as an optional query parameter. This means that it will return the astronomical picture of the day for the specified date.

Again, replace the api_key query parameter’s placeholder with your personal API access token before making the API call.

You can find numerous other NASA APIs at api.nasa.gov.

How can I set up a simple horizontal carousel?

Horizontal Carousel

The response of each API call we used above will either return a link to the image on NASA’s server or an image directly. We can use these links to generate a simple horizontal carousel as follows.

Ext.create('Ext.Carousel', {
     fullscreen: true,
items: [{
         html: '<p><img src="https://apod.nasa.gov/apod/image/2107/PIA24542_fig2_1100c.jpg"></p>'
     }, {
          html: '<p><img src="https://api.nasa.gov/planetary/earth/imagery?lon=100.75&lat=1.5&date=2014-02-01&api_key=<YOUR_API_KEY_HERE>"></p>'
 }, {
 html: '<p><img src="https://apod.nasa.gov/apod/image/2005/CarinaPerspective_Fairbairn_960.jpg"></p>'
 }]
 });

What is an easy way to make a vertically-oriented carousel?

Vertical Carousel

For the vertical carousel, add a new direction key to generate the carousel vertically.

Ext.create('Ext.Carousel', {
     fullscreen: true,
     direction: 'vertical', 
items: [{
         html: '<p><img src="https://apod.nasa.gov/apod/image/2107/PIA24542_fig2_1100c.jpg"></p>'
     }, {
          html: '<p><img src="https://api.nasa.gov/planetary/earth/imagery?lon=100.75&lat=1.5&date=2014-02-01&api_key=<YOUR_API_KEY_HERE>"></p>'
 }, {
 html: '<p><img src="https://apod.nasa.gov/apod/image/2005/CarinaPerspective_Fairbairn_960.jpg"></p>'
 }]
 });

As you can see, creating carousels in JavaScript applications is pretty simple and quick. With minimum code requirements, you can easily create an API-driven image carousel that is dynamic and changes according to the API responses.

Check out the full documentation for building visual stunning carousels with Ext JS.

Ready to get started with Sencha Ext JS? Head over to Sencha Ext JS and create beautiful carousels now.

Recommended Articles

UI Framework vs UI Component Library: Why Enterprise Teams Choose Complete Solutions in 2026

UI frameworks provide complete application architecture with built-in components, routing, and state management, while component libraries offer only UI elements that require a separate framework.…

Front-End Frameworks Compared in 2026: Performance, Use Cases, and Trade-offs

Front-end framework selection in 2026 centers on three critical decisions: complete platform versus ecosystem assembly, performance at enterprise scale, and long-term maintenance costs. Ext JS…

10 Best Enterprise JavaScript Frameworks in 2026: Complete Guide for Fortune 500 Development

Enterprise JavaScript frameworks power the data-intensive applications that Fortune 500 companies depend on. Unlike consumer frameworks, enterprise solutions require robust data grids, comprehensive pre-built component…

How JavaScript Frameworks Are Evolving with AI Coding Tools in 2026

JavaScript frameworks are adapting to AI coding tools in 2026, but enterprise-grade frameworks like Ext JS remain essential for complex applications. While AI assistants excel…

JavaScript Data Structures You Need to Know: Arrays, Objects, Maps, and Sets

Data structures are one of the most important foundations in Enterprise software development. No matter what kind of application you build, you are constantly organizing,…

The Ultimate Guide to JavaScript ES6+ Features You Must Know

JavaScript has evolved dramatically over the years, and ES6+ marks one of the most important leaps in how developers write modern applications using a modern…

View More