in above fig case 1 if i click legend variable to like count the x axis label should change to the legend name likecount
case 2 if i click both legend variable to like count and comment count both the name should be displayed on the x axis label
if this ifs not possible do recommend any other method
I think you should make it as @AIMPED suggested for now.
You can make it a radio button, if likeCount is selected, you pass likeCount into x-axis and if commentCount is chosen, you pass it into the x-axis.
If the order does not matter, you can consider passing likeComment and commentCount to the y-axis instead, that way, you can get what you want when you click on the legend.