1

I am creating a chart in Google Earth Engine showing a vegetation index for a number of different regions. I want to edit the tooltip text so the name of the region is shown, followed by the year, with "VCI:" and then the bold value on the second line rather than the really long number.

How can I edit this tooltip?

var chart_all =
    ui.Chart.image
        .seriesByRegion({
          imageCollection: lt_vci,
          regions: AOI,
          reducer: ee.Reducer.mean(),
          scale: 500,
          xProperty: 'year'
        })
        .setSeriesNames(['VCI'])
        .setOptions({
          title: 'Average Vegetation Condition Index by region ('+ m + '), ' + region,
          hAxis: {title: 'Date', titleTextStyle: {italic: false, bold: true}},
          vAxis: {
            title: 'VCI',
            titleTextStyle: {italic: false, bold: true}
          },
          lineWidth: 1,
          colors: ['e37d05', '1d6b99'],
          curveType: 'function'
        });
print(chart_all);

enter image description here

2 Answers 2

0

I think you can define the series names. at the moment you have this:

.setSeriesNames(['VCI'])

But try if this works:

.setSeriesNames(['series1', 'series2', 'series3']) 

Depending on the amount of variables of course.

2
  • Unfortunately that doesn't work. Also ideally I would like the code to automatically take the region name from the AOI feature class rather than having to put in the names each time. I tried creating a variable to do this and inputting that in the setSeriesNames function but also had no luck
    – Simba06
    Commented Feb 21, 2022 at 8:14
  • Then you should adjust your question and provide an example that actually aims for that.. Hard to reproduce this, but you could consider building a list that contains the names from your AOI feature class
    – Jobbo90
    Commented Feb 21, 2022 at 9:31
0

The solution is to use seriesProperty in ui.Chart.image.seriesByRegion. I set this to the field containing the region names (ADM2_EN) in the feature collection. This code works correctly:

var chart_all =
    ui.Chart.image
        .seriesByRegion({
          imageCollection: lt_vci,
          regions: AOI,
          reducer: ee.Reducer.mean(),
          scale: 500,
          xProperty: 'year',
          seriesProperty: 'ADM2_EN' 
        })
        .setSeriesNames(['VCI'])
        .setOptions({
          title: 'Average Vegetation Condition Index by region ('+ m + '), ' + region,
          hAxis: {title: 'Date', titleTextStyle: {italic: false, bold: true}},
          vAxis: {
            title: 'VCI',
            titleTextStyle: {italic: false, bold: true}
          },
          lineWidth: 1,
//          colors: ['e37d05', '1d6b99'],
          curveType: 'function'
        });
print(chart_all);

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.