Legend - toggle services

Hi,I'm using 'Display identify results in popup' sample and try to display the legend like 'Legend - toggle services' sample. I try to mix the code together and it seem not working. I'm not very good in coding.