[comment]: # translation:outdated

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

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

[comment]: # ({b80d99e9-d2f8406d})
### 描述

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

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

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

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

[comment]: # ({269f47a0-5b1c5b22})
### 参数

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

该方法支持以下参数。

|参数|[类型](/manual/api/reference_commentary#数据类型)|描述|
|--|--|------|
|graphids|ID/array|仅返回具有给定ID的图表。|
|groupids|ID/array|仅返回属于给定主机组或模板组中的主机或模板的图表。|
|templateids|ID/array|仅返回属于给定模板的图表。|
|hostids|ID/array|仅返回属于给定主机的图表。|
|itemids|ID/array|仅返回包含给定监控项的图表。|
|templated|boolean|如果设置为`true`，仅返回属于模板的图表。|
|inherited|boolean|如果设置为`true`，仅返回从模板继承的图表。|
|expandName|flag|图表名称中的扩展宏。|
|selectHostGroups|query|返回一个[`hostgroups`](/manual/api/reference/hostgroup/object)属性，其中包含该图表所属的主机组。|
|selectTemplateGroups|query|返回一个[`templategroups`](/manual/api/reference/templategroup/object)属性，其中包含该图表所属的模板组。|
|selectTemplates|query|返回一个[`templates`](/manual/api/reference/template/object)属性，其中包含该图表所属的模板。|
|selectHosts|query|返回一个[`hosts`](/manual/api/reference/host/object)属性，其中包含该图表所属的主机。|
|selectItems|query|返回一个[`items`](/manual/api/reference/item/object)属性，其中包含该图表中使用的监控项。|
|selectGraphDiscovery|query|返回带有图表发现对象的`graphDiscovery`属性。图表发现对象将图表链接到创建图表的图表原型。<br><br>它具有以下属性：<br>`graphid` - `(ID)` 图表的ID；<br>`parent_graphid` - `(ID)` 创建图表的图表原型的ID；<br>`lastcheck` - `(timestamp)` 上次发现图表的时间；<br>`status` - `(int)` 图表发现状态：<br>0 - *（默认）* 发现了图形，<br>1 - 图表不再被发现；<br>`ts_delete` - `(timestamp)` 不再被发现的图表将被删除的时间。|
|selectGraphItems|query|返回一个[`gitems`](/manual/api/reference/graphitem/object)属性，其中包含该图表中使用的监控项。|
|selectDiscoveryRule|query|返回一个[`graphDiscovery`](/manual/api/reference/drule/object)属性，其中包含创建该图表的低级发现规则。|
|filter|object|仅返回那些与给定过滤器完全匹配的结果。<br><br>接受一个对象，其中键是属性名，值是要匹配的单个值或值数组。<br><br>不支持`text` [数据类型](/manual/api/reference_commentary#数据类型)属性。<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|^|
|selectGroups<br>(deprecated)|query|此参数已弃用，请使用`selectHostGroups` or `selectTemplateGroups` 代替。<br>返回带有图表所属的主机组和模板组的`groups`属性。|

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

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

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

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

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

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

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

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

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

[请求](/manual/api#执行请求)：

```json
{
    "jsonrpc": "2.0",
    "method": "graph.get",
    "params": {
        "output": "extend",
        "hostids": 10107,
        "sortfield": "name"
    },
    "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]: # ({/d11e19d3-e7fae381})

[comment]: # ({e4f07557-e4f96e80})
### 参见

-   [发现规则](/manual/api/reference/discoveryrule/object#发现规则)
-   [图表监控项](/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#模板)
-   [模板组](/manual/api/reference/templategroup/object#模板组)

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

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

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

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