Feature Property Charts

Chart data in a FeatureCollection using one of the methods starting with ui.Chart.feature. Unlike images, features don’t necessarily have a timestamp, so the feature properties to chart must be specified. Use ui.Chart.feature.byProperty() to plot each feature as a different series, with properties on the X-axis. Use ui.Chart.feature.byFeature() to plot specified properties, with features on the X-axis. The following example illustrates the difference between byProperty() and byFeature() by plotting US cities with extreme temperatures in different months:

// Load a table of average seasonal temperatures in U.S. cities.
var seasonalTemps = ee.FeatureCollection('ft:1G3RZbWoTiCiYv_LEwc7xKZq8aYoPZlL5_KuVhyDM');

// Compute the annual temperature delta.
seasonalTemps = seasonalTemps.map(function(city) {
  var julyTemp = ee.Number(city.get('avg_temp_jul'));
  var janTemp = ee.Number(city.get('avg_temp_jan'));
  return city.set('seasonal_delta', julyTemp.subtract(janTemp));

// Select extreme cities by limiting the collection to the most extreme
// values of selected attributes.  Merge the extrema into a new collection.
var extremeCities =
    seasonalTemps.limit(1, 'avg_temp_jan')                 // Coldest.
    .merge(seasonalTemps.limit(1, 'avg_temp_jul', false))  // Hottest.
    .merge(seasonalTemps.limit(1, 'seasonal_delta'));      // Least variation.

// Make a Dictionary of properties and labels to plot
var months = {
  avg_temp_jan: 1,
  avg_temp_apr: 4,
  avg_temp_jul: 7,
  avg_temp_oct: 10

// Make a chart by property.
var chart1 = ui.Chart.feature.byProperty(extremeCities, months, 'city_name')
      title: 'Average Monthly Temperatures in U.S. Cities, by Property',
      hAxis: {
        title: 'Month',
        ticks: [{v: 1, f: 'January'},
                {v: 4, f: 'April'},
                {v: 7, f: 'July'},
                {v: 10, f: 'October'}]
      vAxis: {
        title: 'Temperature (Celsius)'
      lineWidth: 1,
      pointSize: 3

// Make a chart by feature.
var chart2 = ui.Chart.feature.byFeature(extremeCities, 'city_name')
      title: 'Average Monthly Temperatures, by City',
      hAxis: {title: 'City'},
      vAxis: {title: 'Temperature (Celsius)'}

// Print the charts.
print(chart1, chart2);

The first part of this example finds the most extreme cities in terms of average summer or winter temperature and seasonal range. Then the script plots the most extreme cities in each category, either byProperty() or byFeature(). The output should look like Figure 1. The top plot in Figure 1 is the FeatureCollection charted by property, where the properties are arranged on the X-axis using the months dictionary. The bottom plot arranges the features on the X-axis, plotting each property as a different series.

Figure 1. Charts of a FeatureCollection by property (top) and by feature (bottom).


Google Earth Engine API