require_once dirname(__FILE__).'/include/config.inc.php';
$page['file'] = 'chart.php';
$page['type'] = PAGE_TYPE_IMAGE;
require_once dirname(__FILE__).'/include/page_header.php';
'type' => [T_ZBX_INT, O_OPT, null, IN([GRAPH_TYPE_NORMAL, GRAPH_TYPE_STACKED]), null],
'itemids' => [T_ZBX_INT, O_MAND, P_SYS|P_ONLY_ARRAY, DB_ID, null],
'from' => [T_ZBX_RANGE_TIME, O_OPT, P_SYS, null, null],
'to' => [T_ZBX_RANGE_TIME, O_OPT, P_SYS, null, null],
'profileIdx' => [T_ZBX_STR, O_OPT, null, null, null],
'profileIdx2' => [T_ZBX_STR, O_OPT, null, null, null],
'width' => [T_ZBX_INT, O_OPT, null, BETWEEN(CLineGraphDraw::GRAPH_WIDTH_MIN, 65535), null],
'height' => [T_ZBX_INT, O_OPT, null, BETWEEN(CLineGraphDraw::GRAPH_HEIGHT_MIN, 65535), null],
'outer' => [T_ZBX_INT, O_OPT, null, IN('0,1'), null],
'batch' => [T_ZBX_INT, O_OPT, null, IN('0,1'), null],
'onlyHeight' => [T_ZBX_INT, O_OPT, null, IN('0,1'), null],
'legend' => [T_ZBX_INT, O_OPT, null, IN('0,1'), null],
'widget_view' => [T_ZBX_INT, O_OPT, null, IN('0,1'), null],
'resolve_macros' => [T_ZBX_INT, O_OPT, null, IN('0,1'), null]
if (!check_fields($fields)) {
validateTimeSelectorPeriod(getRequest('from'), getRequest('to'));
$itemIds = getRequest('itemids');
$resolve_macros = (bool) getRequest('resolve_macros', 0);
$items = API::Item()->get([
'output' => ['itemid', 'type', 'master_itemid', $resolve_macros ? 'name_resolved' : 'name', 'delay', 'units',
'hostid', 'history', 'trends', 'value_type', 'key_'
'selectHosts' => ['name', 'host'],
foreach ($itemIds as $itemId) {
if (!isset($items[$itemId])) {
$items = CArrayHelper::renameObjectsKeys($items, ['name_resolved' => 'name']);
foreach ($items as &$item) {
$item['hostname'] = $item['hosts'][0]['name'];
$item['host'] = $item['hosts'][0]['host'];
if (!in_array($item['hostname'], $hostNames)) {
$hostNames[] = $item['hostname'];
CArrayHelper::sort($items, ['name', 'hostname', 'itemid']);
$timeline = getTimeSelectorPeriod([
'profileIdx' => getRequest('profileIdx'),
'profileIdx2' => getRequest('profileIdx2'),
'from' => getRequest('from'),