Charting features by a list of properties in Google Earth Engine

feature-collectiongoogle-earth-engineplot

I am trying to create a chart in Earth Engine using the ui.Chart.feature.byFeature function. I am basing my code off of the following example provided by Google Developers…

// Import the example feature collection.
var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example');

// Define the chart and print it to the console.
var chart =
    ui.Chart.feature
        .byFeature({
          features: ecoregions.select('[0-9][0-9]_tmean|label'),
          xProperty: 'label',
        })
        .setSeriesNames([
          'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
          'Nov', 'Dec'
        ])
        .setChartType('ColumnChart')
        .setOptions({
          title: 'Average Monthly Temperature by Ecoregion',
          hAxis:
              {title: 'Ecoregion', titleTextStyle: {italic: false, bold: true}},
          vAxis: {
            title: 'Temperature (°C)',
            titleTextStyle: {italic: false, bold: true}
          },
          colors: [
            '604791', '1d6b99', '39a8a7', '0f8755', '76b349', 'f0af07',
            'e37d05', 'cf513e', '96356f', '724173', '9c4f97', '696969'
          ]
        });
print(chart);

For my feature collection, I have a series of properties (F2010 – F2020) that represent annual values. I would like to use the feature chart function to plot the annual values for each feature in the collection.

The syntax in the Developers example shows the feature class properties indexed using the following language [0-9][0-9]_tmean. I am struggling to make sense of this because there are 12 months of data plotted in this example. I have tried indexing my feaure class properties in a similar manner to isolate the F2010-F2020 properties, but I cannot figure out the proper way to do this.

Here is a snippet of my code…

var chart =
    ui.Chart.feature
        .byFeature({
          features: table.select('F[2010-2020][2010-2020]|County'),
          xProperty: 'County',
        })
        .setChartType('ColumnChart')

Link to Code

What am I doing wrong here?

Best Answer

The problem with your script has to do with understanding how regular expressions are written. In this case, you are interested in selecting all the properties that start with an 'F' and are followed by four numbers ([0-9]{4}). The following expression does exactly that. In addition, notice that the select method should take as an argument a list (defined by the []), where the properties should be separated by a coma.

table.select(['F[0-9]{4}','County'])