@wweverma1,
Setting legendText as legendText: '<?php echo $legendText; ?>'
should work fine in your case.
If you are still facing issue, kindly create sample project reproducing the issue you are facing and share it with us over Google-Drive or Onedrive along with the sample data so that we can run it locally to understand the scenario better and help you out?
—-
Manoj Mohan
Team CanvasJS