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

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.


Now I am trying to add MVVM bindings for a Chart Legend

I have

        <SciChart:SciChartSurface x:Name="sciChart" DataSet="{Binding DataSeriesSet}" 
            RenderableSeries="{Binding RenderableSeries}"
            ChartModifier="{Binding ChartModifier}"
            XAxis="{Binding XAxis}" 
            YAxes="{Binding YAxes}">
        <SciChart:SciChartLegend x:Name="legendControl" Grid.Row="1" Margin="23,23" ShowVisibilityCheckboxes="True" LegendData="{ Binding LegendDataSource,  Mode=OneWay}"/>

and in My ViewModel

        public AnalogueChartViewModel()
            XAxis = new DateTimeAxis
                VisibleRange = RangeFactory.NewRange(DateTime.Now.AddDays(-2), DateTime.Now),
                DrawMinorGridLines = false,
                AxisTitle = "X-Axis"
            RenderableSeries = new ObservableCollection<IRenderableSeries>();
            YAxes = new AxisCollection();
            DataSeriesSet = new DataSeriesSet<DateTime, double>();
            var xAxisDrag = new XAxisDragModifier();
            var zoomExtents = new ZoomExtentsModifier();
            var rubberBandZoom = new RubberBandXyZoomModifier();
            var panModifier = new ZoomPanModifier { ExecuteOn = ExecuteOn.MouseRightButton };
            _legendDataSource = new LegendModifier { GetLegendDataFor = 0 };

            ChartModifier = new ModifierGroup(xAxisDrag, zoomExtents, rubberBandZoom, panModifier, _legendDataSource);


        private LegendModifier _legendDataSource;

        public LegendModifier LegendDataSource
            get { return _legendDataSource; }
                _legendDataSource = value;

But not sure how to bind to the LegendData

Sorry I keep troubling you, but after all this there should be some good MVVM code for others to follow too.

  • You must to post comments

I’ve half answered my own question above by using:-

 <SciChart:SciChartLegend x:Name="legendControl" Grid.Row="1" Margin="23,23" ShowVisibilityCheckboxes="True" LegendData="{ Binding LegendData,  Mode=OneWay}" />


        public ChartDataObject LegendData
            get { return _legendDataSource.LegendData; }
                _legendDataSource.LegendData = value;

But I do not get any axis Name Text on the Legend.How do I add this?

  • Yuriy
    Hi there, Don't worry about troubling - feel yourself free to ask, we are glad to help! :) OK, you need to change a Binding for the legend:
    <SciChart:SciChartLegend x:Name="legendControl" Grid.Row="1" Margin="23,23" ShowVisibilityCheckboxes="True" LegendData="{Binding LegendDataSource.LegendData,  Mode=OneWay}"/>
    This should help, please, try out and let us know, Best regards, Yuriy
  • Yuriy
    Hi, Your solution is working one too - glad you've sorted it out. Text on the legend is bound to your data series name. So you need to have something like that:
                // SeriesName is what will be shown in the legend
                var dataSeries0 = new XyDataSeries<double, double> {SeriesName = "Curve A"};
                var dataSeries1 = new XyDataSeries<double, double> {SeriesName = "Curve B"};
                var dataSeries2 = new XyDataSeries<double, double> {SeriesName = "Curve C"};
    Hope this helps! Regards, Yuriy
  • wilx
    That's Great thanks. I have added it to the AddRemoveAxis example above.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.