图表:图像

命名空间:microsoft.graph

通过缩放图表以适应指定的尺寸,将图表呈现为 base64 编码的图像。

权限

要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限

权限类型 权限(从最低特权到最高特权)
委派(工作或学校帐户) Files.ReadWrite
委派(个人 Microsoft 帐户) 不支持。
应用程序 不支持。

HTTP 请求

GET /me/drive/items/{id}/workbook/worksheets/{id|name}/charts/{name}/image
GET /me/drive/root:/{item-path}:/workbook/worksheets/{id|name}/charts/{name}/image
GET /me/drive/items/{id}/workbook/worksheets/{id|name}/charts/{name}/image(width=640)
GET /me/drive/root:/{item-path}:/workbook/worksheets/{id|name}/charts/{name}/image(width=640)
GET /me/drive/items/{id}/workbook/worksheets/{id|name}/charts/{name}/image(width=640,height=480)
GET /me/drive/root:/{item-path}:/workbook/worksheets/{id|name}/charts/{name}/image(width=640,height=480)
GET /me/drive/items/{id}/workbook/worksheets/{id|name}/charts/{name}/image(width=640,height=480,fittingMode='fit')
GET /me/drive/root:/{item-path}:/workbook/worksheets/{id|name}/charts/{name}/image(width=640,height=480,fittingMode='fit')

请求标头

名称 说明
Authorization Bearer {token}。必需。
Workbook-Session-Id 确定是否保留更改的工作簿会话 ID。可选。

路径参数

在请求正文中,提供具有以下参数的 JSON 对象。

参数 类型 说明
height Int32 生成的图像的所需高度。 可选。
width Int32 生成的图像的所需宽度。 可选。
fittingMode string 如果将高度和宽度都设置为) ,则用于将图表缩放为指定维度的方法 (。 可能的值包括 FitFitAndCenterFill

响应

如果成功,此方法在响应正文中返回 200 OK 响应代码和 base-64 图像字符串。

示例

下面是一个如何调用此 API 的示例。

请求

下面是一个请求示例。

GET https://graph.microsoft.com/v1.0/me/drive/items/{id}/workbook/worksheets/{id|name}/charts/{name}/image(width=640,height=480,fittingMode='fit')
响应

这是一个示例响应。注意:为提高可读性,可能缩短了此处显示的响应对象。

HTTP/1.1 200 OK
Content-type: application/json;odata.metadata=minimal;odata.streaming=true

{
"value" : "base-64 chart image string"
}

用法

可以在 HTML 图像标记内显示 base-64 字符串:<img src="data:image/png;base64,{base-64 chart image string}/>

对于默认行为,请使用 Image(width=0,height=0,fittingMode='fit')。 下面的示例展示了使用默认参数返回的图表图像。

显示使用默认设置和拟合模式设置的饼图显示的屏幕截图。

若要自定义图像的显示方式,请指定高度、宽度和调整模式。 下面展示了使用 Image(width=500,height=500,fittingMode='Fill') 参数检索的同一个图表图像。

显示使用宽度和高度设置为 500 并设置为填充的拟合模式显示的饼图的屏幕截图。