SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Answered
0
0

Hi, I am trying to export an XyScatterRenderableSeries based on a XyzDataSeries<double,double,double> to XPS. The coloring is based on the z value and works perfectly in the application itself. The problem is that when exporting all the data and labels are perfectly visible ( no more vertical mirroring etc.), however all points are grey. I do see by setting a breakpoint on the OverridePointMarker below that the palette is used, just don’t see it in the end result. Anyone any tips or ideas what is going wrong?

Part of the Palette Provider;

    public PointPaletteInfo? OverridePointMarker(IRenderableSeries rSeries, int index, IPointMetadata metadata)
    {
        var rxyz = rSeries as XyScatterRenderableSeries;
        var xyz = rxyz?.DataSeries as XyzDataSeries<double, double, double>;
        if (xyz == null) return null;
        var z = xyz.ZValues[index];
        var i = Convert.ToInt32((_colormap.GetUpperBound(0) * z) / _max);
        var c = _colormap[i];
        return new PointPaletteInfo()
        {
            Fill = c,
            Stroke = c
        };
    }

Code to generate the chart in memory and export it to XPS

        var colormap = new ColorMappingAgain((Brush)Resources["DefaultBrush"], 100);
        var x = new ObservableCollection<IRenderableSeries>() {HeatmapSeries};

        foreach (var y in x)
            y.PaletteProvider = colormap;

        var surface = new SciChartSurface()
        {
            RenderSurface = new XamlRenderSurface(),
            ChartTitle = name,
            FontSize = (double) dpi * fontsize / 96,
            XAxes = xAxes,
            YAxes = yAxes,
            RenderableSeries = x,
        };

        foreach (var y in x)
            y.PaletteProvider = colormap;

        SciChart.ExportToFile(@"C:\Temp\again.xps",ExportType.Xps,true);
        SciChart.ExportToFile(@"C:\Temp\again2.xps", ExportType.Xps, false);
Version
nuget latest
  • You must to post comments
Best Answer
1
1

Hi Michel,

Thanks for your question. The Export feature relies on serialization to create a copy of a SciChartSurface. Some properties cannot be serialized because of the way serialization works. For example, properties of collection and interface types cannot be processed.

So such properties need to be set manually. For this purpose, SciChartSurface exposes the CreateCloneOfSurfaceInMemory(Size) method. Please try overriding it and applying your PaletteProvider to the corresponding RenderableSeries of the cloned SciChartSurface. It can be obtained from the base implementation:

public class SciChartSurfaceEx : SciChartSurface
{
    protected override SciChartSurfaceBase CreateCloneOfSurfaceInMemory(Size newSize)
    {
        var clonedSurface = (SciChartSurface)base.CreateCloneOfSurfaceInMemory(newSize);

        // Apply custom PaletteProvider here
        clonedSurface.RenderableSeries[0].PaletteProvider = new CustomPointMarkerFillPaletteProvider();

        return clonedSurface;
    }
}

Please let us know if this works for you,

Best regards,
Yuriy

  • You must to post comments
1
0

Hi Michel,

Great, I glad it helped. You guessed it right, SciChartSurfaceEx has to be used as your main surface. It gets cloned for exporting. However, it should have worked even if created from code. We do this all the time in tests. Maybe it fails for you due to an exception being thrown?

Concerning the HeatmapColourMap, it is a separate control, so it doesn’t get exported with SciChart. We’ve got a task to improve this.
For now, I think you could try to put the ColourMap into a Legend. Please see this documentation article to learn how to do it.

Let us know if you managed to achieve this,

Best regards,
Yuriy

  • You must to post comments
0
0

Yes,there is some problem when building the surface from scratch. However, your solution worked perfectly when changing the SciChartSurface in XAML to SciChartSurfaceEx and then just calling ExportToXPS. Thank you !!!!

Any idea how I can add a HeatmapColourMap on the export ? đŸ˜€

Thank you so much,

Michel.

  • You must to post comments
0
0

I have implemented the following code which works perfectly as long as the colormap is defined by a static resource. However, colormaps can be changed and thus I need to use binding, the binding works when binding to the Tag of LegendModifier from within the template, I see the map perfectly and beautifully on my chart. Hooray for that. However, when I export I no longer have the filled rectangle on my chart :-/ Any idea how I should update the override of CreateCloneOfSurfaceInMemory to set the programmatically the fill ?

I know this is something that I need to do, but after some hours on this any help or fresh idea is welcome.

Best wishes,

Michel.

  • Yuriy
    Hi Michel, I would suggest adding this as a property on your LegendModifier. You can create a custom one which would extend the existing LegendModifier. It will allow you to bind to this property from within the template and update colors properly from CreateCloneOfSurfaceInMemory. Hope this helps!
  • Michel Bieleveld
    That worked perfectly Yuriy, thank you so much ! Much easier than trying to find logical or visual children. Great way to start the Friday :D
  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.