2

I have read up the guide on getting SciChart to render chart to memory on the support forums. However, the example there uses FastLineRenderableSeries whereas in my project, I am using IRenderableSeriesViewModel with series binding in XAML using ObservableCollection<IRenderableSeriesViewModel>.

When I try to follow the guide at SciChart Knowledgebase, it uses FastLineRenderableSeries as RenderableSeries, and it doesn't work when I try to assign my pre-existing ObservableCollection<IRenderableSeriesViewModel> to RenderableSeries property under SciChartSurface.

I'd like to know if I could simply just use my existing ObservableCollection<IRenderableSeriesViewModel> when I am trying to export my existing plots to bitmap memory. I could just extract the DataSeries again from the IRenderableSeriesViewModel but if there is a faster way to do this, it would be great to know.

Thank you.

EDIT: I am trying to do the export this way, as seen in the Knowledgebase.

My ViewModel currently has this:

private ObservableCollection<IRenderableSeriesViewModel> seriesViewModels =
    new ObservableCollection<IRenderableSeriesViewModel>();

public ObservableCollection<IRenderableSeriesViewModel> SeriesViewModels
{
    get
    {
        return this.seriesViewModels;
    }
}

And as seen in the Knowledgebase,

var series = new FastLineRenderableSeries()
{
    SeriesColor = Colors.Red,
    DataSeries = GetDataSeries()
};

var surface = new SciChartSurface()
{
    ChartTitle = "Rendered In Memory",
    XAxes = xAxes,
    YAxes = yAxes,

    // Here, if I try to use "RenderableSeries = seriesViewModels" it doesn't work.
    RenderableSeries = new ObservableCollection() { series }
};

surface.Width = 1000;
surface.Height = 1000;

// Export to bitmap
var bitmapSource = surface.ExportToBitmapSource();

Visual studio will show this error message:

Cannot implicitly convert type Cannot implicitly convert type > System.Collections.ObjectModel.ObservableCollection<SciChart.Charting.Model.ChartSeries.IRenderableSeriesViewModel> to System.Collections.ObjectModel.ObservableCollection<SciChart.Charting.Visuals.RenderableSeries.IRenderableSeries>

Would you have any suggestion regarding the relation between IRenderableSeries and IRenderableSeriesViewModel?

Kurtis Aung
  • 282
  • 4
  • 14
  • Hi Kurtis, are you using SciChartSurface.ExportToBitmapSource()? Does this work with the binding to ObservableCollection? Care to share a code example? Please edit your question + comment here to notify me – Dr. Andrew Burnett-Thompson Apr 26 '16 at 14:38
  • Thank you Dr. ABT. I have updated my question with the code I'm trying to work with. – Kurtis Aung Apr 27 '16 at 04:39

1 Answers1

1

According to the documentation:

In order to map between ObservableCollection<IRenderableSeriesViewModel> and SciChartSurface.RenderableSeries which is of type ObservableCollection<IRenderableSeries> you need to use the SeriesBinding Markup Extension.

Typically, this is applied in XAML as follows:

<!-- Declare a SciChartSurface with SeriesBinding -->
<!-- Where xmlns:s="http://schemas.abtsoftware.co.uk/scichart -->
    <s:SciChartSurface RenderableSeries="{s:SeriesBinding RenderableSeriesViewModels}">

    <!-- XAxis, YAxis omitted for brevity -->

</s:SciChartSurface>

So the problem becomes 'How to apply a MarkupExtension in code behind', which is fairly difficult by the look of it.

You might be better off creating or styling the SciChartSurface in XAML and using this.FindResource() to get your style and apply it to the chart.

EDIT: UPDATE

Actually, I may have a solution for you. SciChart has the classes RenderableSeriesConverter and RenderableSeriesSourceCollection. Something like this might work:

var surface = new SciChartSurface()
{
    ChartTitle = "Rendered In Memory",
    XAxes = xAxes,
    YAxes = yAxes,

    RenderableSeries = new RenderableSeriesSourceCollection(seriesViewModels);
};

Magique!!

Community
  • 1
  • 1
Dr. Andrew Burnett-Thompson
  • 20,980
  • 8
  • 88
  • 178