I have created a heatmap from points layer's style property. However when I add a legend to the print composer I do not get anything in the legend except the layer name, how can I add the color ramp besides the layer name?
What you can do is create a proxy layer to act as the legend styling.
Being a little creative what you can do is create a new polygon layer with a couple of random shapes. Create the shapes away from your maps focus area because using transparency to hide them will negate this exercise and not show anything in the legend.
In the attributes table of the random shapes layer you can use the ID as a value in the table (
$ID in field calculator) just to give it some scaling values, if you've got 2 shape make sure one is higher than the other. Now use a gradient style on the layer.
Match the gradient colour to your heatmap. Under "Symbol" remove the border style, which will give a smoother gradient impression. Under the "Classes" tab set around 7 - 11. This will give a nice resolution to the gradient in the legend but too many will create quite a large legend item. "Classify" and sort the value in descending order, this will put the darkest colours to the top. Using the invert option will reverse the colour order but it won't match your heatmap!
Now edit the legend labels. There are too many labels to show on gradient so delete the majority. Using an odd number of classes allow for a lowest, highest and middle label. But if you don't need/want the middle label then feel free to change the classes to a even number. Change the labels to also match the values on your heat map.
In the map composer legend properties, hide the heatmap layer and rename the new random shapes layer as the heatmap.
Under "Symbol" set "Symbol Height" to 3.00mm. Under "Spacing" set "Symbol Space" to 0.00mm. This gets the symbols as close as they can possibly get. If the legend is too large you'll have to remove some of the classes but you lose the gradient effect. More classes will improve the gradient whilst lengthening the legend item.