Unfortunately, the resulting PDF file shows just an empty page without chart.However, when I export the chart to PNG, the resulting PNG file correctly shows the chart as it should be.Also, when first exporting the chart to PNG and then to PDF right after that (by uncommenting the code above), the resulting PDF also correctly shows the chart as it should be.

Did I forget some kind of initialization step before exporting the chart to PDF, which is automatically done when exporting the chart to PNG first?