6

I want to make a chart in google earth engine based on monthly NDVI value of one plot. For that i am using the following codes

  function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = ee.Number(2).pow(10).int();
  var cirrusBitMask = ee.Number(2).pow(11).int();

  // Both flags should be set to zero, indicating clear conditions
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(
             qa.bitwiseAnd(cirrusBitMask).eq(0));

  // Return the masked and scaled data.
  return image.updateMask(mask).divide(10000);
}


// Plot Landsat 8 band value means in a section of San Francisco and
// demonstrate interactive charts.

//var sanFrancisco = ee.Geometry.Rectangle(-122.45, 37.74, -122.4, 37.8);

var boundary = ee.FeatureCollection('ft:1T-XrxMki2k49fhQdhMxesWKBoyyUJiKN70pErh9z');// Boundary
var gtpoints = ee.FeatureCollection('ft:1ZvFeFO5jHGo3VExlKNc-kdL-3hmJSeyfLzqLvHhy');//Co-ordinates
var plots = ee.FeatureCollection('ft:1pZJ7v8ek4Z1GP7MxZNA3EhtRVGs5MDgEP6ngwc1v');//Plots
var startdate, enddate;
var NDVI = [];
var ndvi = [];
var month = [];
var mean;
for(var i = 1; i<=12; i++)
{
  startdate = '2017-'+i+'-01'
  enddate = '2017-'+i+'-28'
 // print(startdate, enddate);

var image = ee.ImageCollection(sent2image
.filterDate(startdate,enddate)
.filterBounds(boundary)
//.map(maskS2clouds)
.sort("CLOUD_COVERAGE_ASSESSMENT")
.median());

var mosaic = image.mosaic();
var clip = mosaic.clip(field);

var ND = clip.normalizedDifference(['B8','B4']).rename('nd');

var mean = ND.reduceRegion({
  geometry: field,
  reducer: ee.Reducer.mean(),
  scale: 10
});

mean = mean.get('nd')

month.push(i)
NDVI.push(mean)
}
print(NDVI)
print(month)

var chart = ui.Chart.array.values(ee.Array(NDVI),1)
print(chart)

I am perfectly able to get the mean ndvi values in an array. But i am not able to produce the chart for the same Sharing the link also for my code: https://code.earthengine.google.co.in/00fd8691e53c8ea0c7968276e5f4f5ac

3

Try including new after the equal sign for example:

var chart = new ui.Chart.array.values(ee.Array(NDVI),1) print(chart)

This is inline with the documentation

Earth Engine uses the Google Visualization API to provide support for charting in the ui.Chart class. Charts can be displayed interactively through the Code Editor console, added to user interface components, viewed as separate web pages, or exported as images. Note that ui.Chart is only available in the Code Editor (not in the JavaScript or Python client libraries).

// Define a DataTable using a JavaScript literal.
var dataTable = {
cols: [{id: 'name', label: 'Airport Code', type: 'string'},
     {id: 'year', label: 'Elevation (m)', type: 'number'}],
rows: [{c: [{v: 'SFO'}, {v: 4}]},
     {c: [{v: 'JFK'}, {v: 4}]},
     {c: [{v: 'DEN'}, {v: 1655}]},
     {c: [{v: 'LHR'}, {v: 25}]},
     {c: [{v: 'ZRH'}, {v: 432}]}]
};

Customize chart styles with a dictionary of options, for example:

// Define a dictionary of customization options.
var options = {
title: 'Airport elevations',
vAxis: {title: 'Airport Code'},
legend: {position: 'none'},
hAxis: {
title: 'Elevation (m)',
logScale: true
}
};

Using the constructor, create the chart and print it to display it in the console:

// Make a BarChart from the table and the options.
var chart = new ui.Chart(dataTable, 'BarChart', options);

// Print the chart to display it in the console.
print(chart);

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.