As for the average value, first you should normalize the histogram, that is, the sum of the areas of all rectangles is 1.
Then the area of each rectangle represents the frequency of the abscissa number at the midpoint of its base, so the area multiplied by the abscissa is equivalent to the frequency multiplied by the abscissa, and of course the average value is obtained.