SciChart supports exporting to BitmapSource at a specific size, however, this feature does not work for us because we are using custom types for our chart annotations, and we get the following error:
“Please be advised that SciChart doesn’t handle serialization of objects with properties of interface type, collection type or custom type. You need to implement IXmlSerializable in such objects to have them handled properly.”
We haven’t found any example of how to implement IXmlSerializable in on custom type, and were wondering if some guidelines about what is needed to implement that interface could be provided.
The custom type that we are using is an AnnotatedPointMarker, which inherits the sci chart interface IPointMarker. It consists on a square, marking a data point, plus a text annotation on top, and a small line joining the square and the text.
- malĂș Diaz asked 3 years ago
- You must login to post comments
Hello dear customer,
- During this serialisation process if there are any properties created by you which are not serialisable then they will crash the serializer. That is why the exception message says to implement IXmlSerializable for any custom types.
You need to either mark those with the [ShouldNotSerializeAttribute] attribute to exclude it, or, you need to make your custom classes implement IXmlSerializable and implement WriteXml / ReadXml to serialise this property.
To do so you can take a look at this articles:
–> https://docs.microsoft.com/en-us/dotnet/api/system.xml.serialization.ixmlserializable?view=net-5.0
–> https://www.codeproject.com/Articles/43237/How-to-Implement-IXmlSerializable-Correctly
Finally, there is another workaround. You can mark your properties as [ShouldNotSerialize] and then override SciChartSurface.CreateCloneOfChartInMemory:
When you’re using export with size we internally using our clonning functionality. Cloning functionality will create a clone(copy) of an original SciChartSurface using Xml serialization and deserialization. And then it will use this ‘cloned surface’ to export to stream(file,bitmap etc). So if you’re using some custom annotations, or some customized renderableSeries you will have to implement serialization of those extra components you’ve added, or you have to override CreateCloneOfSurfaceInMemory() method and manually reset those custom elements to the cloned surface. So in your case you can do something like this
// SciChartSurfaceEx is a custom SciChartSurface that you have to use in your application instead SciChartSurface
public class SciChartSurfaceEx : SciChartSurface
{
// SciChartSurface has virtual method CreateCloneOfSurfaceInMemory, that is used in our export
//functionality(when you're exporting with xaml renderer or exporting with specific size)
protected override SciChartSurfaceBase CreateCloneOfSurfaceInMemory(Size newSize)
{
// This will give you, your original surface
var inputSurface = this;
// If you're using for example custom renderableSeries you can get it from your original
//surface and store it in some variable
var myCustomPM = imputSurface.RenderableSeries[0].PointMarker as MyCustomPointMarker;
// This will give you a 'cloned' surface that was made of your original surface
var cloned = (SciChartSurface)base.CreateCloneOfSurfaceInMemory(newSize);
// Here you should reset needed properties from the original Surface to cloned
// Now you can re-set your custom PointMarker to your renderableSeries(lets say it's the first one)
cloned.RenderableSeries[0].PointMarker = myCustomPM ;
// Then you simply return your cloned surface back to exporting function, to proceed with
//exporting
return cloned;
}
}
Please try it that should work.
- Nazariy Pelyushkevych answered 3 years ago
- last edited 3 years ago
- You must login to post comments
Please login first to submit.