1

I have an asset imported from a shapefile in GEE. It is a feature collection with which I wish to chart a time series. The lines from each feature are labelled as system:index. See labelling of picture below and ignore the amount of features, it's a WIP.

enter image description here

I want them to be labelled as the "fid" column in my asset's table. See picture below (column to the right).

enter image description here

Can this be done with .setSeriesNames or some other argument?

Code for chart is the usual, found below.

//// Plot results
var chart = ui.Chart.image.seriesByRegion(
  s2CloudMasked, 
  fc,
  ee.Reducer.median(),
  'NDVI',10)
  .setChartType('LineChart')
  .setSeriesNames([])
  .setOptions({
    interpolateNulls: true,
    lineWidth: 1,
    pointSize: 3,
    title: 'NDVI monthly G3',
    hAxis: {title: 'Date'},
    vAxis: {title: 'NDVI'},
    series: {0:{color: 'red'}
    }
  });
print(chart)

2 Answers 2

2

Turns out I only needed to specify the seriesProperty parameter as "fid":

var chart = ui.Chart.image.seriesByRegion({
  imageCollection: s2CloudMasked,
  band: 'NDVI',
  regions: fc,
  reducer: ee.Reducer.median(),
  seriesProperty: 'fid',
})
1
  • 1
    yeey you are a lifesaver
    – Jan Pisl
    Commented Oct 2, 2023 at 15:27
0

Assuming that 'fid' is unique for each feature, you can simply assign it to the system:index on each feature and it'll get used as the series label. But to do that you have to convert the collection to a list (so that system:index isn't assigned by the collection) and back. You may or may not also need to convert the fid to a string (using ee.Number.format)

fc = ee.FeatureCollection(fc.toList(100).map(function(f) {
  f = ee.Feature(f)
  return f.set("system:index", f.get('fid'))
}))
1
  • Can you update the code for use w/ ee.Number.format? I'm a complete beginner and tried my best alone but no cigar ("ee.Number.Format is not a function"). Commented Mar 8, 2023 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.