Print Charts

Jan 27, 2015 at 5:39 PM
Hi,

Is there any easy way to print the charts?
Tried to use RenderTargetBitmap to render the chart control in a ContentControl (or ViewBox),
but I only get the control with the title not the content (bars) in the image.

Here's some code:
var columnChart = new ClusteredColumnChart();
columnChart.ChartTitle = "My Title";
columnChart.Width = 600;
columnChart.Height = 400;

var columnChartSeries = new ChartSeries();
columnChartSeries.SeriesTitle = "My Series Title";
columnChartSeries.DisplayMember = "Column1";
columnChartSeries.ValueMember = "Column2";
columnChartSeries.ItemsSource = chartData;
columnChart.Series.Add(columnChartSeries);

var contentControl = new ContentControl();
contentControl.Content = columnChart;
contentControl.Measure(new System.Windows.Size(Double.PositiveInfinity, Double.PositiveInfinity));
contentControl.Arrange(new Rect(contentControl.DesiredSize));

var render = new RenderTargetBitmap(600, 400, 96, 96, PixelFormats.Pbgra32);
render.Render(contentControl);
...
same code works fine to show the chart in a WPF window.

Thanks for any help
Harald
Jun 8, 2015 at 12:10 PM
Use the PrintDialog function from WPF itself.