How to create a chart in Excel when exporting a CSV file

Consider creating an Excel file that has space for data, plus a chart pre-defined to use that space for its data. Store that "Excel template" in some gateway-readable folder in your server. Then use the approach described here to fill in the data and deliver the file: