Extract print_chart code into gem and add API endpoint