--- /usr/share/zabbix/include/classes/graphdraw/CLineGraphDraw.php-dd20190517BD	2019-04-29 10:29:31.176943205 +0200
+++ /usr/share/zabbix/include/classes/graphdraw/CLineGraphDraw.php	2019-05-17 16:06:09.359667379 +0200
@@ -1636,6 +1636,11 @@
 				$maxLength = calcMaxLengthAfterDot($calcValues);
 			}
 
+			$padding_left_y_axis_left = 5;
+			$padding_right_y_axis_left = 9;
+			// Recalculate shiftXleft and save axis labels.
+			$labels = [];
+			$dims = [];
 			for ($i = 0; $i <= $hstr_count; $i++) {
 				$hstr_count = ($hstr_count == 0) ? 1 : $hstr_count;
 
@@ -1654,10 +1659,19 @@
 					'ignoreMillisec' => $ignoreMillisec,
 					'length' => $maxLength
 				]);
+				$labels[] = $str;
 
 				if ($side == GRAPH_YAXIS_SIDE_LEFT) {
-					$dims = imageTextSize(8, 0, $str);
-					$posX = $this->shiftXleft - $dims['width'] - 9;
+					$dim = imageTextSize(8, 0, $str);
+					$dims[] = $dim;
+					$this->shiftXleft = max($this->shiftXleft, $dim['width'] + $padding_left_y_axis_left + $padding_right_y_axis_left);
+				}
+			}
+
+			for ($i = 0; $i <= $hstr_count; $i++) {
+				$str = $labels[$i];
+				if ($side == GRAPH_YAXIS_SIDE_LEFT) {
+					$posX = $this->shiftXleft - $dims[$i]['width'] - $padding_right_y_axis_left;
 				}
 				else {
 					$posX = $this->sizeX + $this->shiftXleft + 12;
@@ -2576,6 +2590,11 @@
 
 		$this->initColors();
 		$this->drawRectangle();
+
+		// drawSides() must be used early since it recalculates 
+		// $this->shiftXleft as a workaround for ZBX-1977.
+		$this->drawSides();
+
 		$this->drawHeader();
 		$this->drawWorkPeriod();
 		$this->drawTimeGrid();
@@ -2681,8 +2700,6 @@
 			}
 		}
 
-		$this->drawSides();
-
 		if ($this->drawLegend) {
 			$this->drawTriggers();
 			$this->drawPercentile();
