अपनी स्लाइड में चार्ट जोड़ना

इस पेज पर, Google Sheets से मौजूदा चार्ट लेने और उन्हें Google Slides के प्रज़ेंटेशन में जोड़ने का तरीका बताया गया है.

किसी प्रज़ेंटेशन में चार्ट जोड़ने से, आपको ज़्यादा असरदार बनाने और ऑडियंस के लिए डेटा को काम का बनाने में मदद मिल सकती है. चार्ट, डेटा सेट में पैटर्न या रुझान दिखाने के लिए बेहद कारगर टूल हैं. साथ ही, इनकी मदद से आपको आंकड़ों वाले डेटा के बारे में साफ़ तौर पर जानकारी मिल सकती है.

ऊपर दिए गए वीडियो में स्प्रेडशीट डेटा से स्लाइड जनरेट करने का तरीका बताया गया है. इसमें एक पूरा उदाहरण (Python) दिया गया है, जो किसी स्लाइड में चार्ट जोड़ता है और स्प्रेडशीट सेल का डेटा किसी टेबल में इंपोर्ट भी करता है.

चार्ट जोड़ने के बारे में जानकारी

जब भी आंकड़ों वाले डेटा को प्रज़ेंट किया जाता है, तब डेटा चार्ट से आपके प्रज़ेंटेशन को बेहतर बनाया जा सकता है. Slides API से Google Sheets में बनाया जा सकने वाला कोई भी चार्ट शामिल किया जा सकता है: बार चार्ट, लाइन चार्ट, पाई चार्ट वगैरह.

Slides API प्रज़ेंटेशन में Google Sheets चार्ट जोड़ने का कॉन्सेप्ट

जैसा कि ऊपर दिए गए डायग्राम में दिखाया गया है, आपको सबसे पहले Google Sheets में चार्ट बनाना होगा. चार्ट बन जाने के बाद, उसे अपने प्रज़ेंटेशन में एम्बेड किया जा सकता है.

आपके प्रज़ेंटेशन में चार्ट मैनेज करने की सामान्य प्रोसेस:

  1. Google Sheets में चार्ट बनाएं.
  2. EmbeddedChart का चार्ट आईडी पढ़ने के लिए, Sheets API का इस्तेमाल करें.
  3. किसी स्लाइड में जोड़ने के लिए, एक बार CreateSheetsChartRequest का इस्तेमाल करें.
  4. इसे सोर्स डेटा से सिंक करने के लिए, ज़रूरत के हिसाब से RefreshSheetsChartRequest का इस्तेमाल करें.

स्टैटिक बनाम लिंक किए गए चार्ट

अपने प्रज़ेंटेशन में चार्ट जोड़ने के लिए एपीआई का इस्तेमाल करते समय, आपका तय किया गया एक पैरामीटर LinkingMode होता है. इससे तय होता है कि चार्ट को स्टैटिक इमेज के तौर पर जोड़ा गया है या ऐसे ऑब्जेक्ट के तौर पर जोड़ा गया है जिसे आने वाले समय में रीफ़्रेश किया जा सकता है.

LINKED मोड का इस्तेमाल तब करें, जब:

  • आने वाले समय में, चार्ट को रीफ़्रेश किया जाना चाहिए. इससे, बुनियादी डेटा में हुए बदलाव दिखेंगे.
  • आप चाहते हैं कि सहयोगियों के पास उस स्प्रेडशीट का लिंक हो जिसमें सोर्स चार्ट मौजूद है.

NOT_LINKED_IMAGE (स्टैटिक) मोड का इस्तेमाल तब करें, जब:

  • आपकी इच्छा है कि आने वाले समय में चार्ट में कभी भी बदलाव न हो.
  • आप नहीं चाहते कि सहयोगियों को सोर्स स्प्रेडशीट का लिंक दिखे.

Google Sheets ऐक्सेस करने के स्कोप

जब स्लाइड में कोई चार्ट जोड़ा जाता है, तो Slides API को Google Sheets में उस चार्ट को ऐक्सेस करने की ज़रूरत होती है. इसका मतलब है कि आपके अनुरोध में, इनमें से किसी एक स्कोप का इस्तेमाल किया जाना चाहिए:

  • https://www.googleapis.com/auth/spreadsheets.readonly (पसंदीदा)
  • https://www.googleapis.com/auth/spreadsheets
  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

आम तौर पर, spreadsheets.readonly का इस्तेमाल करना सबसे बेहतर होता है, क्योंकि यह सबसे ज़्यादा पाबंदी वाला होता है. हालांकि, अगर आपका ऐप्लिकेशन पहले से ही ऊपर दिए गए अन्य स्कोप में से किसी एक का इस्तेमाल करता है, तो सिर्फ़ उसी स्कोप का इस्तेमाल करें.

चार्ट जोड़ना

चार्ट जोड़ने के लिए, आपको Google Sheets में चार्ट के स्प्रेडशीट आईडी और चार्ट आईडी की जानकारी होनी चाहिए. इसके बाद, चार्ट को जोड़ने के लिए एक बार CreateSheetsChartRequest का इस्तेमाल करके, batchUpdate तरीके को कॉल करें.

नीचे दिए गए उदाहरण में एक चार्ट लिया गया है और उसे एक स्लाइड में LINKED के रूप में जोड़ा गया है, ताकि उसे बाद में रीफ़्रेश किया जा सके.

Apps Script

slides/api/Snippets.gs
/**
 * Embed a Sheets chart (indicated by the spreadsheetId and sheetChartId) onto
 *   a page in the presentation. Setting the linking mode as 'LINKED' allows the
 *   chart to be refreshed if the Sheets version is updated.
 * @param {string} presentationId
 * @param {string} pageId
 * @param {string} shapeId
 * @param {string} sheetChartId
 * @returns {*}
 */
function createSheetsChart(presentationId, pageId, shapeId, sheetChartId) {
  const emu4M = {
    magnitude: 4000000,
    unit: 'EMU'
  };
  const presentationChartId = 'MyEmbeddedChart';
  const requests = [{
    createSheetsChart: {
      objectId: presentationChartId,
      spreadsheetId: shapeId,
      chartId: sheetChartId,
      linkingMode: 'LINKED',
      elementProperties: {
        pageObjectId: pageId,
        size: {
          height: emu4M,
          width: emu4M
        },
        transform: {
          scaleX: 1,
          scaleY: 1,
          translateX: 100000,
          translateY: 100000,
          unit: 'EMU'
        }
      }
    }
  }];

  // Execute the request.
  try {
    const batchUpdateResponse = Slides.Presentations.batchUpdate({
      requests: requests
    }, presentationId);
    console.log('Added a linked Sheets chart with ID: %s', presentationChartId);

    return batchUpdateResponse;
  } catch (err) {
    // TODO (Developer) - Handle exception
    console.log('Failed with error: %s', err.error);
  }
};

शुरू करें

स्लाइड/स्निपेट/प्रज़ेंटेशन.गो
// Embed a Sheets chart (indicated by the spreadsheetId and sheetChartId) onto
// a page in the presentation. Setting the linking mode as "LINKED" allows the
// chart to be refreshed if the Sheets version is updated.
emu4M := slides.Dimension{Magnitude: 4000000, Unit: "EMU"}
presentationChartId := "MyEmbeddedChart"
requests := []*slides.Request{{
	CreateSheetsChart: &slides.CreateSheetsChartRequest{
		ObjectId:      presentationChartId,
		SpreadsheetId: spreadsheetId,
		ChartId:       sheetChartId,
		LinkingMode:   "LINKED",
		ElementProperties: &slides.PageElementProperties{
			PageObjectId: pageId,
			Size: &slides.Size{
				Height: &emu4M,
				Width:  &emu4M,
			},
			Transform: &slides.AffineTransform{
				ScaleX:     1.0,
				ScaleY:     1.0,
				TranslateX: 100000.0,
				TranslateY: 100000.0,
				Unit:       "EMU",
			},
		},
	},
}}

// Execute the requests.
body := &slides.BatchUpdatePresentationRequest{Requests: requests}
response, _ := slidesService.Presentations.BatchUpdate(presentationId, body).Do()
fmt.Printf("Added a linked Sheets chart with ID %s", presentationChartId)

Java

slides/snippets/src/main/java/CreateSheetsChart.java
import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.slides.v1.Slides;
import com.google.api.services.slides.v1.SlidesScopes;
import com.google.api.services.slides.v1.model.AffineTransform;
import com.google.api.services.slides.v1.model.BatchUpdatePresentationRequest;
import com.google.api.services.slides.v1.model.BatchUpdatePresentationResponse;
import com.google.api.services.slides.v1.model.CreateSheetsChartRequest;
import com.google.api.services.slides.v1.model.Dimension;
import com.google.api.services.slides.v1.model.PageElementProperties;
import com.google.api.services.slides.v1.model.Request;
import com.google.api.services.slides.v1.model.Size;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/* Class to demonstrate the use of Slides Create Chart API */
public class CreateSheetsChart {
  /**
   * Adds chart from spreadsheet to slides as linked.
   *
   * @param presentationId - id of the presentation.
   * @param pageId         - id of the page.
   * @param spreadsheetId  - id of the spreadsheet.
   * @param sheetChartId   - id of the chart in sheets.
   * @return presentation chart id
   * @throws IOException - if credentials file not found.
   */
  public static BatchUpdatePresentationResponse createSheetsChart(
      String presentationId, String pageId, String spreadsheetId, Integer sheetChartId)
      throws IOException {
        /* Load pre-authorized user credentials from the environment.
           TODO(developer) - See https://developers.google.com/identity for
            guides on implementing OAuth2 for your application. */
    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
        .createScoped(Collections.singleton(SlidesScopes.PRESENTATIONS));
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
        credentials);

    // Create the slides API client
    Slides service = new Slides.Builder(new NetHttpTransport(),
        GsonFactory.getDefaultInstance(),
        requestInitializer)
        .setApplicationName("Slides samples")
        .build();

    // Embed a Sheets chart (indicated by the spreadsheetId and sheetChartId) onto
    // a page in the presentation. Setting the linking mode as "LINKED" allows the
    // chart to be refreshed if the Sheets version is updated.
    List<Request> requests = new ArrayList<>();
    Dimension emu4M = new Dimension().setMagnitude(4000000.0).setUnit("EMU");
    String presentationChartId = "MyEmbeddedChart";
    requests.add(new Request()
        .setCreateSheetsChart(new CreateSheetsChartRequest()
            .setObjectId(presentationChartId)
            .setSpreadsheetId(spreadsheetId)
            .setChartId(sheetChartId)
            .setLinkingMode("LINKED")
            .setElementProperties(new PageElementProperties()
                .setPageObjectId(pageId)
                .setSize(new Size()
                    .setHeight(emu4M)
                    .setWidth(emu4M))
                .setTransform(new AffineTransform()
                    .setScaleX(1.0)
                    .setScaleY(1.0)
                    .setTranslateX(100000.0)
                    .setTranslateY(100000.0)
                    .setUnit("EMU")))));

    BatchUpdatePresentationResponse response = null;
    try {
      // Execute the request.
      BatchUpdatePresentationRequest body =
          new BatchUpdatePresentationRequest().setRequests(requests);
      response = service.presentations().batchUpdate(presentationId, body).execute();
      System.out.println("Added a linked Sheets chart with ID " + presentationChartId);
    } catch (GoogleJsonResponseException e) {
      // TODO(developer) - handle error appropriately
      GoogleJsonError error = e.getDetails();
      if (error.getCode() == 404) {
        System.out.printf("Presentation not found with id '%s'.\n", presentationId);
      } else {
        throw e;
      }
    }
    return response;
  }
}

JavaScript

slides/snippets/slides_create_sheets_chart.js
function createSheetsChart(presentationId, pageId, shapeId, sheetChartId, callback) {
  // Embed a Sheets chart (indicated by the spreadsheetId and sheetChartId) onto
  // a page in the presentation. Setting the linking mode as "LINKED" allows the
  // chart to be refreshed if the Sheets version is updated.
  const emu4M = {
    magnitude: 4000000,
    unit: 'EMU',
  };
  const presentationChartId = 'MyEmbeddedChart';
  const requests = [{
    createSheetsChart: {
      objectId: presentationChartId,
      spreadsheetId: shapeId,
      chartId: sheetChartId,
      linkingMode: 'LINKED',
      elementProperties: {
        pageObjectId: pageId,
        size: {
          height: emu4M,
          width: emu4M,
        },
        transform: {
          scaleX: 1,
          scaleY: 1,
          translateX: 100000,
          translateY: 100000,
          unit: 'EMU',
        },
      },
    },
  }];
  // Execute the request.
  try {
    gapi.client.slides.presentations.batchUpdate({
      presentationId: presentationId,
      requests: requests,
    }).then((batchUpdateResponse) => {
      console.log(`Added a linked Sheets chart with ID: ${presentationChartId}`);
      if (callback) callback(batchUpdateResponse.result);
    });
  } catch (err) {
    document.getElementById('content').innerText = err.message;
    return;
  }
}

Node.js

slides/snippets/slides_create_sheets_chart.js
/**
 * Embeds a Sheets chart onto a page in a presentation.
 * @param {string} presentationId The presentation ID.
 * @param {string} pageId The page ID.
 * @param {string} spreadsheetId The spreadsheet ID.
 * @param {string} sheetChartId The sheet's chart ID.
 */
async function createSheetsChart(
    presentationId,
    pageId,
    spreadsheetId,
    sheetChartId,
) {
  const {GoogleAuth} = require('google-auth-library');
  const {google} = require('googleapis');

  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/presentations',
  });

  const service = google.slides({version: 'v1', auth});

  // Embed a Sheets chart (indicated by the spreadsheetId and sheetChartId) onto
  // a page in the presentation. Setting the linking mode as "LINKED" allows the
  // chart to be refreshed if the Sheets version is updated.
  const emu4M = {
    magnitude: 4000000,
    unit: 'EMU',
  };
  const presentationChartId = 'MyEmbeddedChart';
  const requests = [
    {
      createSheetsChart: {
        objectId: presentationChartId,
        spreadsheetId: spreadsheetId,
        chartId: sheetChartId,
        linkingMode: 'LINKED',
        elementProperties: {
          pageObjectId: pageId,
          size: {
            height: emu4M,
            width: emu4M,
          },
          transform: {
            scaleX: 1,
            scaleY: 1,
            translateX: 100000,
            translateY: 100000,
            unit: 'EMU',
          },
        },
      },
    },
  ];

  // Execute the request.
  try {
    const batchUpdateResponse = await service.presentations.batchUpdate({
      presentationId,
      resource: {
        requests,
      },
    });
    console.log(`Added a linked Sheets chart with ID: ${presentationChartId}`);
    return batchUpdateResponse.data;
  } catch (err) {
    // TODO (developer) - Handle exception
    throw err;
  }
}

PHP

slides/snippets/src/SlidesCreateSheetsChart.php
use Google\Client;
use Google\Service\Drive;
use Google\Service\Slides;
use Google\Service\Slides\Request;


function createSheetsChart($presentationId, $pageId, $spreadsheetId, $sheetChartId)
{
    /* Load pre-authorized user credentials from the environment.
       TODO(developer) - See https://developers.google.com/identity for
        guides on implementing OAuth2 for your application. */
    $client = new Google\Client();
    $client->useApplicationDefaultCredentials();
    $client->addScope(Google\Service\Drive::DRIVE);
    $slidesService = new Google_Service_Slides($client);
    // Embed a Sheets chart (indicated by the spreadsheet_id and sheet_chart_id) onto
    // a page in the presentation. Setting the linking mode as "LINKED" allows the
    // chart to be refreshed if the Sheets version is updated.
    try {
        //creating new presentaion chart
        $presentationChartId = 'MyEmbeddedChart';
        $emu4M = array('magnitude' => 4000000, 'unit' => 'EMU');
        $requests = array();
        $requests[] = new Google_Service_Slides_Request(
            array(
                'createSheetsChart' => array(
                    'spreadsheetId' => $spreadsheetId,
                    'chartId' => $sheetChartId,
                    'linkingMode' => 'LINKED',
                    'elementProperties' => array(
                        'pageObjectId' => $pageId,
                        'size' => array(
                            'height' => $emu4M,
                            'width' => $emu4M
                        ),
                        'transform' => array(
                            'scaleX' => 1,
                            'scaleY' => 1,
                            'translateX' => 100000,
                            'translateY' => 100000,
                            'unit' => 'EMU'
                        )
                    )
                )
            ));

        // Execute the request.
        $batchUpdateRequest = new Google_Service_Slides_BatchUpdatePresentationRequest(array(
            'requests' => $requests
        ));
        $response = $slidesService->presentations->batchUpdate($presentationId, $batchUpdateRequest);
        printf("Added a linked Sheets chart with ID: %s\n", $response->getPresentationId());
        return $response;
    } catch (Exception $e) {
        echo 'Message: ' . $e->getMessage();
    }
}

Python

slides/snippets/slides_create_sheets_chart.py
import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError


def create_sheets_chart(
    presentation_id, page_id, spreadsheet_id, sheet_chart_id
):
  """
  create_sheets_chart the user has access to.
  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """
  creds, _ = google.auth.default()
  # pylint: disable=maybe-no-member
  try:
    slides_service = build("slides", "v1", credentials=creds)
    # Embed a Sheets chart (indicated by the spreadsheet_id and
    # sheet_chart_id) onto a page in the presentation.
    # Setting the linking mode as "LINKED" allows the
    # chart to be refreshed if the Sheets version is updated.

    emu4m = {"magnitude": 4000000, "unit": "EMU"}

    presentation_chart_id = "MyEmbeddedChart"
    requests = [
        {
            "createSheetsChart": {
                "objectId": presentation_chart_id,
                "spreadsheetId": spreadsheet_id,
                "chartId": sheet_chart_id,
                "linkingMode": "LINKED",
                "elementProperties": {
                    "pageObjectId": page_id,
                    "size": {"height": emu4m, "width": emu4m},
                    "transform": {
                        "scaleX": 1,
                        "scaleY": 1,
                        "translateX": 100000,
                        "translateY": 100000,
                        "unit": "EMU",
                    },
                },
            }
        }
    ]

    # Execute the request.
    body = {"requests": requests}
    response = (
        slides_service.presentations()
        .batchUpdate(presentationId=presentation_id, body=body)
        .execute()
    )
    print(f"Added a linked Sheets chart with ID: {presentation_chart_id}")
    return response
  except HttpError as error:
    print(f"An error occurred: {error}")
    return error


if __name__ == "__main__":
  # Put the presentation_id, Page_id of slides
  # spreadsheet_id and sheet_chart_id to be submitted.
  create_sheets_chart(
      "10QnVUx1X2qHsL17WUidGpPh_SQhXYx40CgIxaKk8jU4",
      "FIRSTSLIDE",
      "17eqFZl_WK4WVixX8PjvjfLD77DraoFwMDXeiHB3dvuM",
      "1107320627",
  )

Ruby

slides/snippets/lib/file_snippets.rb
# Embed a Sheets chart (indicated by the spreadsheet_id and sheet_chart_id) onto
# a page in the presentation. Setting the linking mode as "LINKED" allows the
# chart to be refreshed if the Sheets version is updated.
emu4M = {
  magnitude: 4000000,
  unit:      'EMU'
}
presentation_chart_id = 'my_embedded_chart'
requests = [{
  create_sheets_chart: {
    object_id_prop:     presentation_chart_id,
    spreadsheet_id:     spreadsheet_id,
    chart_id:           sheet_chart_id,
    linking_mode:       'LINKED',
    element_properties: {
      page_object_id: page_id,
      size:           {
        height: emu4M,
        width:  emu4M
      },
      transform:      {
        scale_x:     1,
        scale_y:     1,
        translate_x: 100000,
        translate_y: 100000,
        unit:        'EMU'
      }
    }
  }
}]

# Execute the request.
req = Google::Apis::SlidesV1::BatchUpdatePresentationRequest.new(requests: requests)
response = slides_service.batch_update_presentation(presentation_id, req)

puts "Added a linked Sheets chart with ID: #{presentation_chart_id}"

चार्ट को रीफ़्रेश करना

अगर आपने अपने प्रज़ेंटेशन में LINKED चार्ट एम्बेड किया है, तो आप उसे RefreshSheetsChartRequest का इस्तेमाल करके किसी भी समय रीफ़्रेश कर सकते हैं. इससे चार्ट अपडेट हो जाता है, ताकि उसे Sheets के मौजूदा चार्ट और उस पर आधारित डेटा के साथ सिंक किया जा सके.

यहां दिया गया उदाहरण एक मौजूदा चार्ट को रीफ़्रेश करता है:

Apps Script

slides/api/Snippets.gs
/**
 * Refresh the sheets charts
 * @param {string} presentationId
 * @param {string} presentationChartId
 * @returns {*}
 */
function refreshSheetsChart(presentationId, presentationChartId) {
  const requests = [{
    refreshSheetsChart: {
      objectId: presentationChartId
    }
  }];

  // Execute the request.
  try {
    const batchUpdateResponse = Slides.Presentations.batchUpdate({
      requests: requests
    }, presentationId);
    console.log('Refreshed a linked Sheets chart with ID: %s', presentationChartId);

    return batchUpdateResponse;
  } catch (err) {
    // TODO (Developer) - Handle exception
    console.log('Failed with error: %s', err.error);
  }
};

शुरू करें

स्लाइड/स्निपेट/प्रज़ेंटेशन.गो
requests := []*slides.Request{{
	RefreshSheetsChart: &slides.RefreshSheetsChartRequest{
		ObjectId: presentationChartId,
	},
}}

// Execute the requests.
body := &slides.BatchUpdatePresentationRequest{Requests: requests}
response, _ := slidesService.Presentations.BatchUpdate(presentationId, body).Do()
fmt.Printf("Refreshed a linked Sheets chart with ID %s", presentationChartId)

Java

slides/snippets/src/main/java/RefreshSheetsChart.java
import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.slides.v1.Slides;
import com.google.api.services.slides.v1.SlidesScopes;
import com.google.api.services.slides.v1.model.BatchUpdatePresentationRequest;
import com.google.api.services.slides.v1.model.BatchUpdatePresentationResponse;
import com.google.api.services.slides.v1.model.RefreshSheetsChartRequest;
import com.google.api.services.slides.v1.model.Request;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/* Class to demonstrate the use of Slides Refresh Chart API */
public class RefreshSheetsChart {
  /**
   * Refresh the sheets charts.
   *
   * @param presentationId      - id of the presentation.
   * @param presentationChartId - id of the presentation chart.
   * @return presentation chart id
   * @throws IOException - if credentials file not found.
   */
  public static BatchUpdatePresentationResponse refreshSheetsChart(
      String presentationId, String presentationChartId) throws IOException {
        /* Load pre-authorized user credentials from the environment.
           TODO(developer) - See https://developers.google.com/identity for
            guides on implementing OAuth2 for your application. */
    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
        .createScoped(Collections.singleton(SlidesScopes.PRESENTATIONS));
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
        credentials);

    // Create the slides API client
    Slides service = new Slides.Builder(new NetHttpTransport(),
        GsonFactory.getDefaultInstance(),
        requestInitializer)
        .setApplicationName("Slides samples")
        .build();

    List<Request> requests = new ArrayList<>();

    // Refresh an existing linked Sheets chart embedded a presentation.
    requests.add(new Request()
        .setRefreshSheetsChart(new RefreshSheetsChartRequest()
            .setObjectId(presentationChartId)));

    BatchUpdatePresentationResponse response = null;
    try {
      // Execute the request.
      BatchUpdatePresentationRequest body =
          new BatchUpdatePresentationRequest().setRequests(requests);
      response = service.presentations().batchUpdate(presentationId, body).execute();
      System.out.println("Refreshed a linked Sheets chart with ID " + presentationChartId);
    } catch (GoogleJsonResponseException e) {
      // TODO(developer) - handle error appropriately
      GoogleJsonError error = e.getDetails();
      if (error.getCode() == 400) {
        System.out.printf("Presentation chart not found with id '%s'.\n", presentationChartId);
      } else if (error.getCode() == 404) {
        System.out.printf("Presentation not found with id '%s'.\n", presentationId);
      } else {
        throw e;
      }
    }
    return response;
  }
}

JavaScript

slides/snippets/slides_refresh_sheets_chart.js
function refreshSheetsChart(presentationId, presentationChartId, callback) {
  const requests = [{
    refreshSheetsChart: {
      objectId: presentationChartId,
    },
  }];
  // Execute the request.
  try {
    gapi.client.slides.presentations.batchUpdate({
      presentationId: presentationId,
      requests: requests,
    }).then((batchUpdateResponse) => {
      console.log(`Refreshed a linked Sheets chart with ID: ${presentationChartId}`);
      if (callback) callback(batchUpdateResponse.result);
    });
  } catch (err) {
    document.getElementById('content').innerText = err.message;
    return;
  }
}

Node.js

slides/snippets/slides_refresh_sheets_chart.js
/**
 * Refreshes an embedded sheet chart.
 * @param {string} presentationId The presentation ID.
 * @param {string} presentationChartId The presentation's chart ID.
 */
async function refreshSheetsChart(presentationId, presentationChartId) {
  const {GoogleAuth} = require('google-auth-library');
  const {google} = require('googleapis');

  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/presentations',
  });

  const service = google.slides({version: 'v1', auth});

  const requests = [
    {
      refreshSheetsChart: {
        objectId: presentationChartId,
      },
    },
  ];

  // Execute the request.
  try {
    const batchUpdateResponse = await service.presentations.batchUpdate({
      presentationId,
      resource: {
        requests,
      },
    });
    console.log(
        `Refreshed a linked Sheets chart with ID: ${presentationChartId}`,
    );
    return batchUpdateResponse.data;
  } catch (err) {
    // TODO (developer) - Handle exception
    throw err;
  }
}

PHP

slides/snippets/src/SlidesRefreshSheetsChart.php
use Google\Client;
use Google\Service\Drive;
use Google\Service\Slides;
use Google\Service\Slides\BatchUpdatePresentationRequest;

function refreshSheetsChart($presentationId, $presentationChartId)
{
    /* Load pre-authorized user credentials from the environment.
       TODO(developer) - See https://developers.google.com/identity for
        guides on implementing OAuth2 for your application. */
    $client = new Google\Client();
    $client->useApplicationDefaultCredentials();
    $client->addScope(Google\Service\Drive::DRIVE);
    $slidesService = new Google_Service_Slides($client);
    try {

        $requests = array();
        $requests[] = new Google_Service_Slides_Request(array(
            'refreshSheetsChart' => array(
                'objectId' => $presentationChartId
            )
        ));

        // Execute the request.
        $batchUpdateRequest = new Google_Service_Slides_BatchUpdatePresentationRequest(array(
            'requests' => $requests
        ));
        $response = $slidesService->presentations->batchUpdate($presentationId, $batchUpdateRequest);
        printf("Refreshed a linked Sheets chart with ID: %s\n", $response->getPresentationId());
        return $response;
    } catch (Exception $e) {
        echo 'Message: ' . $e->getMessage();
    }
}

Python

slides/snippets/slides_refresh_sheets_chart.py
import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError


def refresh_sheets_chart(presentation_id, presentation_chart_id):
  """
  refresh_sheets_chart the user has access to.
  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """
  creds, _ = google.auth.default()
  # pylint: disable=maybe-no-member
  try:
    slides_service = build("slides", "v1", credentials=creds)
    # Refresh an existing linked Sheets chart embedded in a presentation.
    requests = [{"refreshSheetsChart": {"objectId": presentation_chart_id}}]

    # Execute the request.
    body = {"requests": requests}
    response = (
        slides_service.presentations()
        .batchUpdate(presentationId=presentation_id, body=body)
        .execute()
    )
    print(f"Refreshed a linked Sheets chart with ID:{presentation_chart_id}")
    return response
  except HttpError as error:
    print(f"An error occurred: {error}")
    return error


if __name__ == "__main__":
  # Put the presentation_id, presentation_chart_id
  # to be submitted.
  refresh_sheets_chart(
      "10QnVUx1X2qHsL17WUidGpPh_SQhXYx40CgIxaKk8jU4", "1107320627"
  )

Ruby

slides/snippets/lib/file_snippets.rb
# Refresh an existing linked Sheets chart embedded in a presentation.
requests = [{
  refresh_sheets_chart: {
    object_id_prop: presentation_chart_id
  }
}]

# Execute the request.
req = Google::Apis::SlidesV1::BatchUpdatePresentationRequest.new(requests: requests)
response = slides_service.batch_update_presentation(presentation_id, req)

puts "Refreshed a linked Sheets chart with ID: #{presentation_chart_id}"