[comment]: # ({cdc53a5f-cdc53a5f})
# graph.get

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

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

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

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

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

:::

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

[comment]: # ({a6a52487-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 | 返回一个[groups](/manual/api/reference/hostgroup/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`属性，包含图形发现object. 图形发现objects将图形与其创建来源的图形原型关联.<br><br>具有以下属性:<br>`graphid` - `(string)` 图形ID;<br>`parent_graphid` - `(string)` 创建该图形的图形原型ID. |
| selectGraphItems | query | 返回一个[gitems](/manual/api/reference/graphitem/object)属性，包含图形中使用的监控项. |
| selectDiscoveryRule | query | 返回一个[discoveryRule](/manual/api/reference/drule/object)属性，包含创建该图形的低级发现规则. |
| filter | object | 仅返回完全匹配给定过滤条件的结果.<br><br>接受一个array，其中键为属性名，值为要匹配的单个值或array值数组.<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]: # ({/a6a52487-5b1c5b22})

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

`(integer/array)` 返回以下两种情况之一:

-   一个包含array的objects数组;
-   检索到的objects数量，如果使用了`countOutput`参数。

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

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

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

[comment]: # ({b4388e3f-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]: # ({/b4388e3f-e7fae381})

[comment]: # ({e4f96e80-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#模板)

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

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

CGraph::get() 位于 *ui/include/classes/api/services/CGraph.php* 文件中。

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