I am trying to grab the underlying data from a chart in GEE. It looks like there is a built in method for this: ui.Chart.getDataTable(), however it appears to not work. I've tried on multiple charts. Here's the documentation for the function. Here is my code:

var start = '2021-01-01';
var end = '2022-12-31';

// Construct a polygon from a list of x,y coordinate pairs defining a boundary.
var roi2 = ee.Geometry.Polygon(
  [-110.0, 40, -113.0, 40, -110.0, 42]
Map.addLayer(roi2, {}, 'roi2');

// Snow water equivalent - daily
var dayMet = ee.ImageCollection("NASA/ORNL/DAYMET_V4")
  .select('prcp', 'swe')   
  .filterDate(start, end)

// Save the chart as a variable
var dayMetChart = (ui.Chart.image.series(dayMet.select(['prcp', 'swe']), roi,
      ee.Reducer.mean(), 4000)
    title: 'dayMet',
    lineWidth: 1,
    pointSize: 3

// Use the getDataTable function and print the data
var table = dayMetChart.getDataTable();

The table variable is an empty object. Can someone explain why this doesn't work or how to get it to work?


1 Answer 1


It looks as a bug not fixed yet. However, you can use 'reduceRegion', as follows, for obtaining each column used to print the chart.

var dayMet_lst = dayMet.toList(dayMet.size());

var datatable = dayMet_lst.map(function (ele){
  var date = ee.Date(ee.Image(ele).get("system:time_start")).format().slice(0,10);
  var values = ee.Image(ele).reduceRegion(ee.Reducer.mean(), roi2, 4000);
  return [date, values.get('prcp'), values.get('swe')];

print('datatable', datatable);

After running complete code, it can be obtained the following result. Data table was printed as a list with three columns: date, prcp and swe.

enter image description here

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.