Fixing temperature Issues on I3 Mega / Where to find spare part
The plastic looks ok.  If you get the tools and pins to work on the connector, you could replace problem pins.  Many of us build our own cables.  If we verify the connector is Molex, you might need calipers to measure dimensions to get the correct size.  You won't need expensive ones.  I've seen digital calipers from \$10 to \$20.
Have you already verified your sensor and heater aren't an issue?  Maybe you've tried a new hot end, or a new heater block with a new heater and sensor.
You can visually inspect the pins on the connector to see if they have a loose connection.  See the solution at Proper hotend heater for Reprap x400 Pro V3
What is strange from you graph, you seem to be loosing connection to both thermistors.  Do the thermistors to the bed and hot end share one common connection, so that one pin could affect both?
If you haven't already tried it, one quick fix to try is unplugging the cables and plug them in again with the printer off of course.