Remaining battery charge percentage measurement is definitely biased towards voltage since there is no known way to easily measure how much current is still contained in a Lithium Ion battery (at least not without incredibly sophisticated laboratory equipment) - but instead only how much is being consumed at any given time based on the load and how much has been consumed over time cumulatively. Voltage on the other hand can be used as a relatively accurate indicator of charge levels by iterative solution based on two targets...the fully charged static voltage level (open circuit), and the fully discharged static voltage level (open circuit), or less accurately using closed (or loaded), circuit voltages at the same points. It's that difference which can be used, in combination with an algorithm based on the rated capacity (for a new battery), or the actual diminished capacity (for an older battery), to determine approximately where in the charged to discharged range the battery sits at any one time.
Unfortunately that is only a rough guess since the voltage drop or difference between fully charged and what is dictated as discharged is a very small number (4.2 versus 3 for instance). Trying to measure those slight differences over many hours can result in lots of error. So the manufacturers try to use a combination of what's being consumed over time, coupled with known minimum and maximum values and using constant voltage readings to moderate or supplement these measurements. But a big part of that is knowing most accurately what "full" looks like (voltage), and what "empty" looks like (voltage again). Without a revisit of those minimum and maximum levels on an infrequent basis, things can start to stray off-course and eventually the estimated charge levels can be very far from the actual ones, resulting in the apparent sudden loss of charge you experienced. Unfortunately that's not all...battery power that is consumed faster will waste energy in the form of heat, so a battery that's used quickly will give off less cumulative total usable current from full to empty than one that is drawn on slowly.
In your case, the phone had not seen both a full charge (powered off), and a full discharge immediately subsequent to each other in so long it lost track of what either of them looked like (voltages), and so it was guessing along the way based on cumulative consumption and dynamic voltage readings...a recipe for failure. Once the voltages reached a level that were far lower than the estimated charge levels it would expect during discharge using the old and outdated values from the last "full" and "empty" level indications, it quickly started dropping the charge level indication to "catch up", eventually leading to a full collapse and potential deep-discharge. If the battery is discharged too low (voltages much lower than 3V), the battery can actually shut down completely and become unable to take a charge at all.
So the still bigger question is, how does one accurately measure remaining current (% of remaining charge), in a battery while it is being charged and used at varying levels of load (use)? Likewise, while charging the battery's voltages can fluctuate due to the phone consuming power at varying rates during the charge cycle and this can "fool" the charger into thinking the battery has reached full charge prematurely thereby stopping the charge at less than maximum capacity. This then results in a voltage used to indicate "full" which is lower than the true "full" voltage level, and then estimates of charge level using two variables that are wrong, and so the result will obviously be wrong as well. This is why it's recommended to do the full charge to 100% with the phone powered off every so often (2-3 months), followed by using it till it displays the "Connect your charger" indication on the screen, and then charging again to 100% with power off to set those high and low "flags" accurately for future reference in the meter's estimations. So it's very important that you re-train your battery's meter to what are the accurate full and empty levels, so it can more accurately estimate what the remaining charge is at any given time.
As for why the meter may show lower remaining charge first (voltages) and then higher values afterwards (spikes in the graph), it is a factor of voltage suppression. If I were to measure at any one time, I may be measuring during or right after a large load period (such as playing a video that's streaming over the internet via cellular towers), and then later I may be measuring during a period where use was very low (such as while at rest). This is where the meter can indicate low levels followed by higher ones. If you read voltage during a period of high consumption due to a large load (high resistance), and then read it again once that load has been removed, the voltages will go from low to higher making it appear like the battery has suddenly and miraculously recharged itself - increased its stored energy. Of course, that's not at all what has happened. Voltage levels are impacted by current draw such that during high consumption or demand (large load), voltage levels will appear lower than during normal load or demand;
When you are drawing little to no current you will get an artificially high voltage (known as open circuit voltage).
When you measure voltages with a load that is an average representation of typical current consumption the voltage reported will be lower (loaded circuit or "Operating" voltage).
When you measure voltage while current is being consumed at an abnormally high rate, the voltages will be artificially lower (load-suppressed voltage).
When under a load, voltages naturally are "pulled down" some, the greater the load, the lower the voltage. Once the load is removed, those voltages will recover some - maybe not back to their pre-load levels but certainly above their loaded ones. To prevent those up and down spikes in the graph, some manufacturers choose to set thresholds at voltages as they're dropping, so as the voltages dip below each whole percentage or fractional voltage, the meter is prevented from displaying any higher readings later (unless actual charging has been detected), thereby preventing this artificial self-charging syndrome.