Implementing the renderChart method

Finally, let's now implement the most important piece of our puzzle, the renderChart method. We will code it together piece by piece as follows:

  1. First of all, we need to retrieve the selections made by the user in the chart form. We can do so using the view's getChartFormDetails method:
console.log("Rendering the chart"); 
const chartFormDetails = this._view.getChartFormDetails(); 

Of course, we need to make sure that there are no errors:

if (chartFormDetails.error) { 
    console.error("Failed to retrieve the chart details",      chartFormDetails.error); 
    return; 
} 
  1. Furthermore, we can also verify that all the properties that we expected are defined and available:
if (!chartFormDetails.countryId || !chartFormDetails.indicator ...

Get Learn TypeScript 3 by Building Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.