I'm using the XamDataChart with a common legend similar to many of the examples in both the help and Feature Browser. When copying the chart to the clipboard, the legend is not included in the image. Is there a different approach to either building the legend or copying the chart that will include the legend?
Thanks, Steve
My Xaml looks like this:
<ig:XamDock x:Name="xmDockContainer" Margin="10">
<ig:XamDataChart x:Name="xmDataChart"
Legend="{Binding ElementName=xmLegend}"
Margin="10,10,10,10">
<ig:XamDataChart.Series>
<ig:LineSeries Title="Volume Series"
ItemsSource="{Binding}"
ValueMemberPath="Volume"
XAxis="{Binding ElementName=xmXAxis}"
YAxis="{Binding ElementName=xmYAxis2}">
</ig:LineSeries>
<ig:FinancialPriceSeries Title="Price Series"
DisplayType="Candlestick"
OpenMemberPath="Open"
CloseMemberPath="Close"
HighMemberPath="High"
LowMemberPath="Low"
VolumeMemberPath="Volume"
YAxis="{Binding ElementName=xmYAxis}">
</ig:FinancialPriceSeries>
</ig:XamDataChart.Series>
</ig:XamDataChart>
<ig:Legend x:Name="xmLegend"
Content="Common Legend"
Margin="10"
ig:XamDock.Edge="InsideRight">
</ig:Legend>
</ig:XamDock>
My copy to clipboard code looks like this:
RenderTargetBitmap bmp = new RenderTargetBitmap((int)xmDataChart.ActualWidth, (int)xmDataChart.ActualHeight, 96, 96, PixelFormats.Default);
bmp.Render(xamDataChart);
Clipboard.Clear();
Clipboard.SetImage(bmp);
You should pass the dock panel to RenderTargetBitmap rather than the chart. The chart doesn't contain the legend. The dock contains both.
Hope this helps!
-Graham
Hello,
I have been investigation into your issue and you are giving the RenderTargetBitmap constructor an instance of the XamDataChart object. However the Legend is a separate object and the Legend property of the xamDataChart is just bound to that object. When you are giving the xamDataChart instance to the RenderTargetBitmap, it simply cannot figure out that you want to copy the additional Legend object as well.
What you can do is but both the xamDataChart and the Legend in some sort of container or some other suitable structure, so you can pass it to the RenderTargetBitmap constructor.
In the following sample code I am placing the two objects in a grid and passing the hole grid to the RenderTargetBitmap constructor:
<Grid Name="grid1" Background="White">
Height="269" Width="463">
….
<ig:Legend x:Name="xmLegend" Content="Common Legend" Height="69" Width="119"></ig:Legend>
</Grid>
And in the code-behind copy logic:
RenderTargetBitmap bmp = new RenderTargetBitmap((int)grid1.ActualWidth, (int)grid1.ActualHeight, 96, 96, PixelFormats.Default);
bmp.Render(grid1);
Notice that I have explicitly set the Background property of the grid. I am doing this, because if I do not set it, it will get the default Transparent value and this can lead to unpredictable results then pasting, because this transparent color will be interpreted variously in the different programs. For example if I paste it in MS Paint the background will immediately become black.
If you have any other concerns on that matter, please do not hesitate to ask us.
Sincerely,
Ekaterina
Developer Support Engineer
Infragistics Inc.
www.infragistics.com/support
Hello ,
I have a close problem. I try to export my datachart as an image with the code below;
RenderTargetBitmap bmp = new RenderTargetBitmap((int)xamDataChart1.ActualWidth, (int)xamDataChart1.ActualHeight, 96, 96, PixelFormats.Default);
PngBitmapEncoder png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(bmp));
But the bottom part of the datachart does not fit to image.
(int)xamDataChart1.ActualWidth = 1120
(int)xamDataChart1.ActualHeight = 426
So what I am missing?
Thanks
Thanks, Ekaterina. That worked for me.