Where does the data come from?
As RedGrittyBrick already wrote, the difficulty to create new blocks is adjusted every 2016 blocks. The difficulty provides an expected amount of hashes performed to find a block, which allows a general estimate how much hashrate exists on the network. Additionally, some websites compare the number of published blocks with the expected number of blocks found to provide a higher resolution than whole difficulty periods. Since blocks are found in a random process, these charts often jump around a lot as even a constant hashrate can have a large variance of blocks found per day.
As an example, let's take a look at this chart of Blocks per Day for the last three months. The blocks found range from 89 on 2022-12-24 to 180 on 2023-01-06.
Meanwhile, the self-reported hashrate of mining pools in the last three months looks like this:
While we do see a drop in the self-reported hashrate on Christmas Eve (partially explained by an extreme winter freeze in Texas that had miners yield power for heating homes) that aligns with the lowest block count, the self-reported hashrate ranges between 200 EH/s and 287 EH/s while the block count maximum is double the minimum.
This is underscored when we compare the self-reported figures with miningpoolstats.stream's estimated hashrate on the network:
So, the hashrate can be estimated from the difficulty of the blocks and the count of blocks found, but the random process makes it easy estimate much larger swings than seem to be present in the actual hashrate.
The total network hashrate can be estimated from the network difficulty recorded in the block headers over a reasonable sample period.
There is a relationship between the two because the difficulty is adjusted every 2016 blocks (about two weeks at 10 minutes per block) with the aim of keeping block production rate near constant as total network hashrate changes.