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

0
0

I need to export a load of images from one graph. Export from the View is very long. So, I’ve implemented the export in memory like in this example:
https://support.scichart.com/index.php?/Knowledgebase/Article/View/17213/34/rendering-chart-to-bitmap-in-memory

Export is fast and flexible. One of my axes has a custom label provider, but I see a default axis labels after export. Export from View gives correct label values. Here is the code of the label provider:

public class MyCustomLabelProvider: NumericLabelProvider
{

    public override string FormatLabel(IComparable dataValue)
    {
        return string.Format("{0:" + this.ParentAxis.TextFormatting + "}", 1 / (double)dataValue);
    }

    public override string FormatCursorLabel(IComparable dataValue)
    {
        return string.Format("{0:" + this.ParentAxis.TextFormatting + "}", 1 / (double)dataValue);
    }
}

And a code of export:

    var sciChartSurface = new SciChartSurface();
    ThemeManager.SetTheme(sciChartSurface, "BrightSpark");
    sciChartSurface.YAxes = new AxisCollection()
    {
        new NumericAxis()
        {
            AxisAlignment = AxisAlignment.Left,
            VisibleRangeLimitMode = RangeClipMode.MinMax,
            LabelProvider = new MyCustomLabelProvider(),
            DrawMajorGridLines = false,
            DrawMinorGridLines = false,
            DrawMajorBands = false,
        }
    };
    sciChartSurface.XAxes = new AxisCollection()
    {
        new NumericAxis()
        {
            AxisAlignment = AxisAlignment.Bottom,
            LabelProvider = new CurvatureLabelProvider(),
            VisibleRangeLimitMode = RangeClipMode.MinMax,
            DrawMajorGridLines = false,
            DrawMinorGridLines = false,
            DrawMajorBands = false
        }
    };

    sciChartSurface.RenderableSeries = new ObservableCollection<IRenderableSeries>()
    {
        new FastLineRenderableSeries() { DataSeries = lineSeries, Stroke = Colors.Green }
    };

    ...

    sciChartSurface.XAxes.FirstOrDefault().VisibleRange = new DoubleRange(0, 100);
    sciChartSurface.ExportToFile(Path.Combine(folderPath, $"Object.png"), ExportType.Png, false, new Size(1500, 750));

Any suggestions?

Version
5.3
  • You must to post comments
0
0

Any help? It is an urgent task for me.

I’ve attached a test project to demonstrate it

Attachments
  • You must to post comments
0
0

Hi Alexander,

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. You have to override it and reapply LabelProvider to a copy of the surface that is to be exported. 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 LabelProvider here

        return clonedSurface;
    }
}

Hope this helps.

  • Alexander Erkabaev
    Hi, thanks for your reply, but it throws an exception “An error occurred when using serialization to clone a chart for export to file. Please check the inner exception for details.” on CreateCloneOfSurfaceInMemory
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.