I have tried to select only shrubs and grass on NDVI but on plotting chart it shows this error. Here is the code.
var feat =ee.Geometry.Point([33.15865673674562, -5.173302054347385]);
var s2a = ee.ImageCollection('COPERNICUS/S2_SR')
.filter(ee.Filter.date('2019-01-01', '2020-12-30'))
.select('B1','B2','B3','B4','B5','B6','B7','B8','B8A','B9','B11','B12')
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10))
.map(function(s2a){return s2a.clip(feat)});
Map.setCenter (6.3690,34.8888,5);
var s2a_median = s2a.median()
.clip(feat);
var nir = s2a_median.select('B8');
var red = s2a_median.select('B4');
var ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI');
// Display the result.
var ndvi2 =ndvi
.where(ndvi.gt(0.18).and(ndvi.lte(0.22)), 2)
.where(ndvi.gt(0.22).and(ndvi.lte(0.27)), 3);
// var wrd=ndvi2.clip(feat)
var subndvi=ndvi2.clip(feat)
// var NDVI = s2a.map(
// function(img) {
// // var ndvi2 =ndvi
// // .where(ndvi.gt(0.18).and(ndvi.lte(0.22)), 2)
// // .where(ndvi.gt(0.22).and(ndvi.lte(0.27)), 3);
// return img.normalizedDifference(['B8','B4'])
// .rename('NDVI')
// .copyProperties(img, ['system:time_start']);
// });
Map.addLayer(subndvi,{min: -1000, max: 5000, palette: ['00FF00','000000']},'Sub County',true)
// Create a NDVI chart.
var ndviChart2 = ui.Chart.image.series(subndvi, feat, ee.Reducer.mean(), 1000);
ndviChart2.setOptions({
title: 'Mean NDVI of area',
vAxis: {title: 'NDVI', maxValue: 1},
hAxis: {title: 'date', format: 'MM-yy', gridlines: {count: 7}},
maxPixels:90e9,
});
Error is! The
Error generating chart: No features contain non-null values of "system:time_start".