[comment]: # translation:outdated

[comment]: # ({cdc53a5f-cdc53a5f})
# 获取

[comment]: # ({/cdc53a5f-cdc53a5f})

[comment]: # ({79f4abc8-d2f8406d})

### 描述

`integer/array graph.get(object parameters)`

该方法允许根据给定的参数来检索图表。

::: noteclassic
此方法对任何类型的用户可用。可以在用户角色设置中撤销调用该方法的权限。更多信息请查看[用户角色](/manual/web_interface/frontend_sections/administration/user_roles)。
:::

[comment]: # ({/79f4abc8-d2f8406d})

[comment]: # ({b1f7453f-5b1c5b22})

### 参数

`(object)` 参数定义了所需的输出。

该方法支持以下参数。

|参数|[类型](/manual/api/reference_commentary#数据类型)|描述|
|---------|---------------------------------------------------|-----------|
|graphids|string/array|只返回具有给定ID的图表。|
|groupids|string/array|只返回属于给定主机组中的主机的图表。|
|templateids|string/array|只返回属于给定模板的图表。|
|hostids|string/array|只返回属于给定主机的图表。|
|itemids|string/array|只返回包含给定监控项的图表。|
|templated|boolean|如果设置为`true`，只返回属于模板的图表。|
|inherited|boolean|如果设置为`true`，只返回从模板继承的图表。|
|expandName|flag|在图表名称中扩展宏。|
|selectGroups|query|返回一个[组](/manual/api/reference/hostgroup/object)属性，其中包含该图表所属的主机组。|
|selectTemplates|query|返回一个[模板](/manual/api/reference/template/object)属性，其中包含该图表所属的模板。|
|selectHosts|query|返回一个[主机](/manual/api/reference/host/object)属性，其中包含该图表所属的主机。|
|selectItems|query|返回一个[监控项](/manual/api/reference/item/object)属性，其中包含该图表中使用的监控项。|
|selectGraphDiscovery|query|返回一个 `graphDiscovery` 属性和图表发现对象。图表发现对象将图表和创建图标的原型联系起来。<br><br>它具有以下属性：<br>`graphid` - `(string)` 图表的ID；<br>`parent_graphid` - `(string)` 创建图表的图表原型的ID。|
|selectGraphItems|query|返回一个[图表监控项](/manual/api/reference/graphitem/object)属性，其中包含该图表中使用的监控项。|
|selectDiscoveryRule|query|返回一个[发现规则](/manual/api/reference/drule/object)属性，其中包含创建该图表的低级发现规则。|
|filter|object|只返回那些与给定过滤器完全匹配的结果。<br><br>接受一个数组，其中键是属性名称，而值是其匹配的单一的值或一个数组的值。<br><br>支持额外的过滤器：<br>`host` - 图表所属主机的技术名称；<br>`hostid` - 图表所属主机的ID。|
|sortfield|string/array|按给定的属性对结果进行排序。<br><br>可用值： `graphid`, `name` 和 `graphtype`。|
|countOutput|boolean|这些参数对所有的 "get "方法均是通用的，在[参考说明](/manual/api/reference_commentary#通用get方法参数)页面中有详细描述。|
|editable|boolean|^|
|excludeSearch|boolean|^|
|limit|integer|^|
|output|query|^|
|preservekeys|boolean|^|
|search|object|^|
|searchByAny|boolean|^|
|searchWildcardsEnabled|boolean|^|
|sortorder|string/array|^|
|startSearch|boolean|^|

[comment]: # ({/b1f7453f-5b1c5b22})

[comment]: # ({7223bab1-7223bab1})

### 返回值

返回 `(integer/array)` 其中之一：

-   一个对象的数组；
-   如果使用了 `countOutput` 参数，则为检索到的对象的数量。

[comment]: # ({/7223bab1-7223bab1})

[comment]: # ({b41637d2-b41637d2})

### 示例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({9dfc40db-e7fae381})
#### 从主机上检索图表

检索主机 "10107 "的所有图表，并按名称排序。

请求：

```json
{
    "jsonrpc": "2.0",
    "method": "graph.get",
    "params": {
        "output": "extend",
        "hostids": 10107,
        "sortfield": "name"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "graphid": "612",
            "name": "CPU jumps",
            "width": "900",
            "height": "200",
            "yaxismin": "0",
            "yaxismax": "100",
            "templateid": "439",
            "show_work_period": "1",
            "show_triggers": "1",
            "graphtype": "0",
            "show_legend": "1",
            "show_3d": "0",
            "percent_left": "0",
            "percent_right": "0",
            "ymin_type": "0",
            "ymax_type": "0",
            "ymin_itemid": "0",
            "ymax_itemid": "0",
            "flags": "0"
        },
        {
            "graphid": "613",
            "name": "CPU load",
            "width": "900",
            "height": "200",
            "yaxismin": "0",
            "yaxismax": "100",
            "templateid": "433",
            "show_work_period": "1",
            "show_triggers": "1",
            "graphtype": "0",
            "show_legend": "1",
            "show_3d": "0",
            "percent_left": "0",
            "percent_right": "0",
            "ymin_type": "1",
            "ymax_type": "0",
            "ymin_itemid": "0",
            "ymax_itemid": "0",
            "flags": "0"
        },
        {
            "graphid": "614",
            "name": "CPU utilization",
            "width": "900",
            "height": "200",
            "yaxismin": "0",
            "yaxismax": "100",
            "templateid": "387",
            "show_work_period": "1",
            "show_triggers": "0",
            "graphtype": "1",
            "show_legend": "1",
            "show_3d": "0",
            "percent_left": "0",
            "percent_right": "0",
            "ymin_type": "1",
            "ymax_type": "1",
            "ymin_itemid": "0",
            "ymax_itemid": "0",
            "flags": "0"
        },
        {
            "graphid": "645",
            "name": "Disk space usage /",
            "width": "600",
            "height": "340",
            "yaxismin": "0",
            "yaxismax": "0",
            "templateid": "0",
            "show_work_period": "0",
            "show_triggers": "0",
            "graphtype": "2",
            "show_legend": "1",
            "show_3d": "1",
            "percent_left": "0",
            "percent_right": "0",
            "ymin_type": "0",
            "ymax_type": "0",
            "ymin_itemid": "0",
            "ymax_itemid": "0",
            "flags": "4"
        }
    ],
    "id": 1
}
```

[comment]: # ({/9dfc40db-e7fae381})

[comment]: # ({a1d5c57c-e4f96e80})

### 另见

-   [发现规则](/manual/api/reference/discoveryrule/object#discovery_rule)
-   [图表监控项](/manual/api/reference/graphitem/object#图表监控项)
-   [监控项](/manual/api/reference/item/object#监控项)
-   [主机](/manual/api/reference/host/object#主机)
-   [主机组](/manual/api/reference/hostgroup/object#主机组)
-   [模板](/manual/api/reference/template/object#模板)

[comment]: # ({/a1d5c57c-e4f96e80})

[comment]: # ({6f7b2d0a-6f7b2d0a})

### 来源

*ui/include/classes/api/services/CGraph.php* 中的 CGraph::get()。

[comment]: # ({/6f7b2d0a-6f7b2d0a})
