O'Reilly logo

Going GAS by Bruce Mcpherson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 12. Charts

In Excel, manipulating charts makes up a fairly large part of the VBA footprint. When Apps Script for Sheets first became available, a number of services, including charts, made use of the UIApp service to embed visualizations and create UIs. The UIApp was deprecated in 2014, and these services have partially or fully migrated to alternative solutions (HtmlService, for example), or have been deprecated themselves (UIApp builder).

There are two ways of creating charts in Sheets. One is to use the EmbeddedChartBuilder, and another is to use the charts available in the Google Visualization API (which can be used from HtmlService). As with all Google services, it’s hard to predict which (if either) will be deprecated first, but given the reach of the Visualization API, and the continuing focus on Add-ons and other HtmlService-client-based capabilities, I would put my money on the Google Visualization API as the preferred way to create charts in the future.

Using the combination of the Google Visualization API and the HtmlService Dialog UI, you can create charts very much like the ones built by EmbeddedChartBuilder.

Chart Data

For these examples, I’ll use Table 12-1, which shows US domestic passengers flown by each airline in 2014. There are 125 airlines in the dataset, but I’ll concentrate on the top 10.

Table 12-1. US domestic passengers flown by each airline in 2014
Name Passengers (000) Carrier
Southwest Airlines Co. 126,746 WN
Delta Air Lines Inc. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required