Suppose the table is of x height and y width.
If I have to construct a chair for that table, how would I know what height should it be?
Woodworking Stack Exchange is a question and answer site for professional and amateur woodworkers. It only takes a minute to sign up.Sign up to join this community
You want the user's hands to rest just above the table. Given that, the distance from the elbow of the sitter to seat of the pants will determine the top of the seat and in turn, the length of the legs.
Mind you, as BenjaminR pointed out, there is variety among humans, even more so if you consider children as well. I'm a fan of Chairmaking & Design by Jeff Miller, which has number of suggestions on the topic.
You may wish to look at Is there a procedure or equation to calculate optimal height of a seat based on a given person?
This depends on whether you're building furniture for a general population or a specific individual. An individual can tune their furniture to their body. If this is the case and the furniture is for a specific person, you can follow advice from Is there a procedure or equation to calculate optimal height of a seat based on a given person? as others have suggested, or you can simply work with the person to find where they're comfortable, by visiting a furniture store or having the person sit in an adjustable chair to find the height they're comfortable at.
If you don't know who will be using your furniture, you need to go for the average person to make your table fit the largest portion of the population possible. To that end, there are "approximate" standards, which are suggestions and an inch or two in either direction won't have a significant impact.
A typical dining room has a table at 30 inches and a floor to seat height of 18 inches for the chairs. A typical desk height is 29 inches, and a typical office chair is adjustable, but extrapolating, an average desk chair height would be 17 inches.
More generally (from How to Choose the Right Size Dining Chairs)
Regarding table and chair height:
Allow 12 inches between the seat of your chair and your tabletop.
This in particular is the answer to your question. Given a table of x height, the chair seat should be approximately x-12 inches. I would not go with a smaller distance, but one or maybe two inches lower would be OK.
Leave 7 inches between the chair arm and the bottom or apron of the table.
Regarding chair width:
Provide each guest 24-30 inches at the dining table.
For rectangular tables, add an extra 12 inches at each end for those seated at the head and foot of the table.