Add flour spoonful by spoonful, and the number of grams goes up in lockstep. That's entirely predictable because it's the same stuff that you're adding each time: the flour has a density.
Mass and volume are constrained, linked by a constant density. Spoon in sugar instead, and the mass increases by more for each spoonful, but still in lockstep because sugar has a greater density.
Change one, and you necessarily change the other. The impossibility of doing anything else is a discovery about the world. The line on the graph is one way of writing this; a mathematical relationship is another.
mass = density × volume