The relation shown in the 2nd diagram is a function. The reason for this is that one and only one y-value is associated with each x-value.
Note that this is not true of the first diagram. If x=0, there are two separate y vaues associated: -1 and 2. This clearly states that the first diagram does not represent a function.