How should I attach a chin-up bar to floor joists?
If you use several lag bolt of sufficient size, you probably would be OK, but that is not a preferred method.

The load will be concentrated on the threads of the lag bold and the wooden fibers holding the threads. Bolts and screws are much stronger when the load pulls perpendicular to the axis of the fastener instead of parallel to it.  This then relies on the shear strength of the fastener. Basically to pull such bolt(s) out, you need enough load to cut the bolt(s) in half, which is much higher than the load needed to rip through the wood holding the threads.

If you use a 2x4 spanning mount, the same rules apply.  Attaching them to the bottom of the joist is again depending on the strength of the thread in wood, not the strength of the bolt itself. Putting them over the bottom plate of the joist and lag bolting them sideways uses the shear strength and is a much stronger setup.

A 2x4 laid flat (with its 3 1/2" side running horizontal) is not its stronger configuration. It is much stronger and less prone to flex if you set it on edge (with its 1 1/2" edge horizontal). But it is hard to drill a decent size bolt hole through the 1 1/2" edge, and it weakens the piece. You probably need to lay it flat.  If the span is wide and if your attachment point are not close to the joist face, consider stacking two pieces on their flat sides.

If you use that approach, you shouldn't just screw lag bolts up into the 2x4s.  Instead, drill through them completely and use a conventional bolt and nut with oversize washers on the tops of the 2x4s.  This spreads the load over a much larger area (several inches instead of fractions of an inch).