I've calculated NDVI from Sentinel 2 images but when I try to get the chart of the series this message is generated - Error generating chart: No features contain non-null values of "system:time_start". The code is the following:
var s2 = ee.ImageCollection('COPERNICUS/S2')
.filterDate('2019-01-01', '2019-12-31')
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
.filterBounds(studyArea);
function getNDVI (image) {
var ndvi = image.normalizedDifference(['B8','B4']).rename("ndvi");
image = image.addBands(ndvi);
return image;
}
s2 = s2.median();
s2 = getNDVI(s2).clip(studyArea);
var s2NDVI = s2.select('ndvi');
print(s2NDVI);
var NDVIseries = ui.Chart.image.seriesByRegion(
s2NDVI, studyArea, ee.Reducer.mean(), 'ndvi', 200, 'system:time_start', 'label')
.setChartType('ScatterChart')
.setOptions({
title: 'NDVI 2016',
vAxis: {title: '-1+1'},
lineWidth: 1,
pointSize: 4,
series: {
0: {color: 'FF0000'},
}});
// Display.
print(NDVIseries);
Can somebody help me to fix the code?