0

I made several collection and I want to make a line chart using these five period.

var p1 = S2.filterDate('2020-04-14','2020-04-27').mean();
Map.addLayer(p1.clip(SBY), band_viz, 'PERIODE 1');

var p2 = S2.filterDate('2020-04-28','2020-05-11').mean();
Map.addLayer(p2.clip(SBY), band_viz, 'PERIODE 2');

var p3 = S2.filterDate('2020-05-12','2020-05-25').mean();
Map.addLayer(p3.clip(SBY), band_viz, 'PERIODE 3');

var p4 = S2.filterDate('2020-05-26','2020-06-08').mean();
Map.addLayer(p4.clip(SBY), band_viz, 'PERIODE 4');

var p5 = S2.filterDate('2020-06-09','2020-06-22').mean();
Map.addLayer(p5.clip(SBY), band_viz, 'PERIODE 5');

var period = p1.addBands(p2).addBands(p3).addBands(p4).addBands(p5);


var options = {
 title: 'Grafik Rata-Rata Kadar NO2 Per Periode',
 hAxis: {title: 'Periode Waktu'},
 vAxis: {title: 'Rata-Rata Kadar NO2 (mol/m2)'},
 lineWidth: 1,
 pointSize: 4,
 };

var Periode = ['Periode 1', 'Periode 2', 'Periode 3', 'Periode 4', 'Periode 5'];

var chart = ui.Chart.image.regions(
  period, SBY, ee.Reducer.mean(), 30, 'label', Periode)
   .setChartType('ScatterChart')
   .setOptions(options);


print(chart);


But instead I got this enter image description here

How can my chart to have just a single line representing the mean of each period?

1 Answer 1

1

Instead of combining your periods to a single image, you can put them in an image collection and use ui.Chart.image.series().

var periods = ee.ImageCollection([
  p1.set('period', 'Periode 1'),
  p2.set('period', 'Periode 2'),
  p3.set('period', 'Periode 3'),
  p4.set('period', 'Periode 4'),
  p5.set('period', 'Periode 5'),
])

var chart = ui.Chart.image.series({
  imageCollection: periods, 
  region: SBY, 
  reducer: ee.Reducer.mean(), 
  scale: 30, 
  xProperty: 'period'
})

https://code.earthengine.google.com/95cf279dbffa2c615fecb69b4fbd968a

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.