1

I would like to change the label of the chart in Google Earth Engine. I had the code:

var image= ee.FeatureCollection('ft:1OXpMKiwvIBC__iYcgjyW23A2oMr89IQlC3cLqk3q')
     .filter(ee.Filter.or(ee.Filter.eq('name', 'Lake Tekapo')));
print (image);
var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
            .filterBounds(image)
            .filterDate('2017-01-01','2017-05-01');
// Map a function over the Landsat 8 TOA collection to add an NDVI band.
function test(image) {
  var equation = image.expression(
    '(7.27 * B4/B3) - 1.7',
    {
        B3: image.select('B4'),    
        B4: image.select('B3'),   
    }).rename('TEST').float();
  return image.addBands(equation).set('system:time_start', 
image.get('system:time_start'));
}
var test =collection.map(test).select(['TEST']);
print (test,'median');
//CHART TIME SERIES
 // Define customization options.
var options = {
  title: 'TEST over time in regions',
  hAxis: {title: 'Time'},
  vAxis: {title: 'TEST values'},
  lineWidth: 1,
  series: {
    0: {color: '00FF00'},
    1: {color: '0000FF'}, 
}};
// Create a time series chart.
var tempTimeSeries = ui.Chart.image.seriesByRegion(
    test, image, ee.Reducer.mean(), 'TEST',300)
  .setChartType('LineChart')
      .setOptions(options);
// Display.
print(tempTimeSeries);

I would like that the chart of the lable is the property name of the feature (name = Lake Tekapo) instead of the Id of the feature (id = 2819) (see the figure attached).

enter image description here

  • 1
    I got the answer. // Create a time series chart. var tempTimeSeries = ui.Chart.image.seriesByRegion( test, image, ee.Reducer.mean(), 'TEST',300, 'system:time_start','name') – user30985 Apr 19 '18 at 13:31
  • Please post this as an answer instead of a comment and mark it as accepted. This way people finding this question in the future will find the answer easier. – Kersten Apr 20 '18 at 11:27
1

Series labels are defined by the parameter seriesProperty (the 7th 'Argument' in the syntax) for ui.Chart.image.seriesByRegion function. You just have to specify the name of the column that describes names of the lakes and it should work as long as it is specified in the 7th slot. If there are certain arguments which you don't want to specify (and are not mandatory), you can leave them as 'undefined'. So in your case the following should work,

**var** tempTimeSeries = ui.Chart.image.seriesByRegion(test, image, ee.Reducer.mean(), 'TEST', 300, **undefined**, INSERT COLUMN NAME HERE)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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