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

0
0

Hello,

I have a collection of IAxisViewModel that I would like to be bound to the XAxes or YAxes of the chart. I don’t use the AxisBiding markup, everything is code behind.

For example, the following must be bound to the ScichartSurface.XAxes :

 public ReadOnlyObservableCollection<IAxisViewModel> XAxes;

Unfortunately Scichart.XAxes is waiting a type of AxisCollection but the only way to read a collection of IAxisViewModel is to use your AxesSourceCollection.

At first I thought that this would be possible :

public ReadOnlyObservableCollection<IAxisViewModel> XAxes;

ctor()
{
    var xAxesSourceCollection = new AxesSourceCollection(ViewModel.XAxes);
    sciChartSurface.XAxes = xAxesSourceCollection ;
}

But it is not.
The last resort is to bind the created xAxesSourceCollection. Using ReactiveUI bindings, it is possible to do the following :

xAxesSourceCollection.ToObservableChangeSet()
                    .ObserveOn(RxApp.MainThreadScheduler)
                    .OnItemAdded(x => sciChartSurface.XAxes.Add(x))
                    .OnItemRemoved(x => sciChartSurface.XAxes.Remove(x))
                    .Subscribe()

Meaning that I subscribe to the changes of the created xAxesSourceCollection and when a new axis is added/removed, I add/remove it from the XAxes collection of the scichart surface. See image “Without numericAxis”

Everything works fine when I remove an axis but things do not work when I add an axis. The axis is well added in the scichartSurface collection but the axis is not displayed (the major bands/minor bands are). If I use a singleton view model and refresh the whole control, the axes are visible meaning that something inside the scichart surface with the NumericAxisForMVVM is broken.

Even more, if I replace the previous code by this one :

xAxesSourceCollection.ToObservableChangeSet()
                    .ObserveOn(RxApp.MainThreadScheduler)
                    .OnItemAdded(x => sciChartSurface.XAxes.Add(new NumericAxis() 
                    { 
                        IsPrimaryAxis = x.IsPrimaryAxis,
                        Id = x.Id,
                        AxisTitle = x.AxisTitle
                    }))
                    .OnItemRemoved(x => sciChartSurface.XAxes.Remove(x))
                    .Subscribe()

It works as expected because I have replaced the NumericAxisForMVVM by a NumericAxis breaking the link between the view model and the view. See image “With numericAxis”

How can I fix the following ?

Two images are below

Version
6.5.1.26063
Images
  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.