Accurate estimation of building electricity consumption (BEC) is essential for sustainable urban development and effective energy management. Existing methods, which rely on using physical models or small-scale surveys, often lack the accuracy and reliability required to provide meaningful insights at the city-scale building level. To address this gap, we introduce a data-driven framework combining electricity consumption data from meters with building footprint data. This framework, implemented in the megacity of Dongguan, China, utilizes five advanced machine learning algorithms to estimate BEC for residential, commercial, and industrial buildings. Our results show that the random forest (RF) model outperforms other algorithms, with building volume identified as the primary predictor. Spatially, residential BEC decreases from urban centers to suburban and rural areas, while commercial BEC exhibits polarization, with high concentrations in central urban areas and key commercial towns. Although industrial BEC is widespread, it shows localized high-consumption clusters. At the community level, BEC patterns exhibit strong spatial autocorrelation, with distinct hot spots and cold spots observed for residential, commercial, and industrial BEC, despite significant variations in their spatial distributions. Both total BEC and BEC intensity exhibit log-normal distribution characteristics across building types. In terms of median BEC intensity, commercial and industrial buildings consume 3.2 times and 5 times more electricity per unit area, respectively, compared to residential buildings. This study advances the accurate estimation of BEC at the building level for multiple building types within a Chinese megacity, providing valuable insights for sustainable urban planning and energy efficiency policies.