I'm trying to color a cube based on it's distance from another object along the z axis. I can color the cube based on it's own z axis, but when I try to reference another object (e.g. the plane in the below image), the entire cube is shaded the same color. Please let me know what I'm doing wrong.
That's because you are using Object's Texture Coordinates, which determine how an image is placed upon the faces, while you need Object's Cartesian Coordinates.
Texture Coordinates usually vary from one point to the other. Referring to the picture below we can see how the gradient is assigning to each point at the same Z the same value. Every little step has it's own value.
The distance of an object to another involves instead Cartesian Coordinates, which is a single triplet of values (the coordinates of the object origin) that are the same for all object's point.
Ideally you should base your distance calculation upon the Cartesian Coordinates and use the resulting vector to tweak the Texture Coordinates, but as the Texture Coordinates (option Object) is already consiedering the position of the Object, I would just reference the plane.
When the distance between the two origins increases the Object is coloured with the highest value of the color ramp.
Subtracting the position of the Cube object would allow instead to use the plane as an "absolute" controller of the gradient. Moving the cube alone would not change the gradinent mapping upon its faces.