Knowledgebase: Export to Bitmap
Exporting chart with legend to bitmap
Posted by Admin - on 21 March 2014 11:20 AM

As you probably now SciChart have such feature as showing legend. To do this you need to add LegendModifier to your chart and add SciChartLegend control which shows legend information. This approach has one disadvantage – because SciChartSurface and SciChartLegend are separated control you can’t save them to same bitmap. The most obvious way to omit this problems is to create some panel such as Grid, place chart and legend there and save to bitmap screenshot of that panel.

We want to show you another get to get the same result without significant changes to your application. To do it we will use CustomAnnotation. We’ll place legend there so when we’ll try to save chart to bitmap we save also legend.

<visuals:SciChartSurface Name="surface" visuals:ThemeManager.Theme="ExpressionLight">

    <visuals:SciChartSurface.RenderableSeries>

        <visuals:FastLineRenderableSeries SeriesColor="#279B27" />

        <visuals:FastLineRenderableSeries SeriesColor="#FF1919" />

        <visuals:FastLineRenderableSeries SeriesColor="#1964FF" />

    </visuals:SciChartSurface.RenderableSeries>

    <visuals:SciChartSurface.XAxis>

        <visuals:NumericAxis />

    </visuals:SciChartSurface.XAxis>

    <visuals:SciChartSurface.YAxis>

        <visuals:NumericAxis />

    </visuals:SciChartSurface.YAxis>

    <visuals:SciChartSurface.ChartModifier>

        <visuals:ModifierGroup>

            <visuals:LegendModifier x:Name="legendModifier" GetLegendDataFor="AllSeries" />

            <chartPrintingExample:ExportToBitmapModifier/>

        </visuals:ModifierGroup>

    </visuals:SciChartSurface.ChartModifier>

    <!--  Annotation with Legend  -->

    <visuals:SciChartSurface.Annotations>

        <visuals:CustomAnnotation X1="0" Y1="300">

            <visuals:CustomAnnotation.ContentTemplate>

                <DataTemplate>

                    <visuals:SciChartLegend x:Name="legendControl"

                                    Margin="20,20"

                                    LegendData="{Binding LegendData,

                                                         ElementName=legendModifier,

                                                         Mode=OneWay}" />

                </DataTemplate>

            </visuals:CustomAnnotation.ContentTemplate>

          

        </visuals:CustomAnnotation>

    </visuals:SciChartSurface.Annotations>

</visuals:SciChartSurface>

 

 

Results of saving chart with annotation to bitmap

NOTE: During axis interactions when you’re changing axis VisibleRange annotation can move because it uses X and Y data coordinates not pixel coordinates. So when you’re using this approach you should update coordinate of annotation when changing VisibleRange of axis. To do this you can use value converter which bind X1 coordinate to min of x axis visible range and the same for Y1 coordinate or you can use HitTest API to update annotation position.

 

 

(0 vote(s))
Helpful
Not helpful

CONTACT US

Not sure where to start? Contact us, we are happy to help!


CONTACT US

SciChart Ltd, 16 Beaufort Court, Admirals Way, Docklands, London, E14 9XL. Email: Legal Company Number: 07430048, VAT Number: 101957725