Theory
A histogram bar's area represents frequency. Its height is frequency density, so frequency = class width x frequency density. A tall narrow bar need not contain more observations than a shorter wide bar.
After finding each class frequency, use the class midpoint as a representative value. Multiply midpoint x frequency for each class and add these products.
Divide the total of midpoint x frequency by the total frequency. Write 'estimated mean' because the actual values within each class are unknown.
In the diagram, 0-10 has density 2, 10-30 has density 1, and 30-40 has density 3. Their frequencies are 20, 20 and 30, not 2, 1 and 3.
Always check the widths first. Using bar heights as frequencies gives the wrong mean when intervals have unequal widths.