refactored legend code by binding data properly to parent