1

I'm trying to graph a time series of weather indices obtained from the Gridmet Drought product, but am getting the following error: Error generating graph: Data columns for axis #0 cannot be of type string.

This is my script:

var GRIDMET = ee.ImageCollection("GRIDMET/DROUGHT")
.filter(ee.Filter.date('2010-02-18', '2022-06-26'))
.filterBounds(PNI)
.select('spi30d','eddi30d','spei30d','pdsi','z');

print(GRIDMET);

var GRIDMET_2 = GRIDMET.map(function(image) {
  return image.set('timeFormat', image.date().format('dd-MM-yyyy'))});
  
print(GRIDMET_2);

var SPI = ui.Chart.image.seriesByRegion(
GRIDMET_2, PNI.geometry().bounds(), ee.Reducer.mean(), 'spi30d', 1000, 'timeFormat', 'label')
  .setChartType('ScatterChart')
  .setOptions({
    title: 'SPI a través del tiempo',
    hAxis: { title: 'Tiempo'},
    vAxis: {title: 'SPI'},
    lineWidth: 1});
   
print(SPI)

1 Answer 1

1

You don't provide access to your PNI variable so, I think your problem is in it. By using your code with an arbitrary PNI area in USA (with 2 features) as follows:

var geometry1 = ee.Geometry.Polygon(
        [[[-99.74885326262063, 41.2959303393308],
          [-99.74885326262063, 41.01468579876124],
          [-99.37531810637063, 41.01468579876124],
          [-99.37531810637063, 41.2959303393308]]], null, false),
    geometry2 = ee.Geometry.Polygon(
        [[[-98.77107005949563, 41.41138604975184],
          [-98.77107005949563, 41.02297491656624],
          [-98.24372630949563, 41.02297491656624],
          [-98.24372630949563, 41.41138604975184]]], null, false);

var PNI = ee.FeatureCollection([ee.Feature(geometry1, {label: 'area1'}), 
                                ee.Feature(geometry2, {label: 'area2'})]);

Map.centerObject(PNI, 9);

var GRIDMET = ee.ImageCollection("GRIDMET/DROUGHT")
.filter(ee.Filter.date('2010-02-18', '2022-06-26'))
.filterBounds(PNI)
.select('spi30d','eddi30d','spei30d','pdsi','z');

print(GRIDMET);

var GRIDMET_2 = GRIDMET.map(function(image) {
  return image.set('timeFormat', image.date().format('dd-MM-yyyy'))});
  
print(GRIDMET_2);

var SPI = ui.Chart.image.seriesByRegion(
  GRIDMET_2, PNI, ee.Reducer.mean(), 'spi30d', 1000, 'timeFormat', 'label')
  .setChartType('ScatterChart')
  .setOptions({
    title: 'SPI a través del tiempo',
    hAxis: { title: 'Tiempo'},
    vAxis: {title: 'SPI'},
    lineWidth: 1});
   
print(SPI)

the chart is produced without any problem; as it can be observed in following picture:

enter image description here

Complete code can also be accessed here.

3
  • My PNI variable is a shapefile of a national park in Argentina. Here's a link to download it: drive.google.com/drive/folders/…. I tried your script and I didn't have a problem either, so I think it's a problem with the shapefile, but not mine in particular because I tried many of them and they all give me the same error. Thank you!
    – Rocío
    Commented Sep 4, 2023 at 16:36
  • I need access for downloading it.
    – xunilk
    Commented Sep 4, 2023 at 19:48
  • The script won't work for your shapefile in Argentina because the product GRIDMET/DROUGHT is only valid for across the contiguous United States.
    – xunilk
    Commented Sep 5, 2023 at 3:15

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.