Explain how you would write a custom function to automate data visualization for a weekly portfolio report.