I would like to dynamically add and remove columns from a ColumnRenderableSeriesViewModel in code behind.
I am using MVVM and the SeriesBinding. I assigned a XyDataSeries<double, double> to the ColumnRenderableSeriesViewModel .DataSeries.
The chart initially draws all the bars for each item in the XYDataSeries, but If I append or remove one of them, the chart does not update and show the new bar or remove the old bar.
Here is my XAML:
<s:SciChartSurface RenderableSeries="{s:SeriesBinding RenderableSeries}">
<s:SciChartSurface.XAxis>
<s:NumericAxis />
</s:SciChartSurface.XAxis>
<s:SciChartSurface.YAxis>
<s:NumericAxis />
</s:SciChartSurface.YAxis>
</s:SciChartSurface>
And some of my view model:
using SciChart.Charting.Model.ChartSeries;
using SciChart.Charting.Model.DataSeries;
using System.Collections.ObjectModel;
namespace ChartExample {
public class ChartViewModel {
ColumnRenderableSeriesViewModel _seriesViewModel = new ColumnRenderableSeriesViewModel();
XyDataSeries<double, double> _dataSeries = new XyDataSeries<double, double>();
public ChartViewModel() {
RenderableSeries.Add(_seriesViewModel);
_seriesViewModel.DataSeries = _dataSeries;
}
public ObservableCollection<IRenderableSeriesViewModel> RenderableSeries { get; } = new ObservableCollection<IRenderableSeriesViewModel>();
public void AddSeries() {
_dataSeries.Append(_dataSeries.Count, _dataSeries.Count);
}
public void RemoveSeries(int seriesIndex) {
_dataSeries.RemoveAt(seriesIndex);
}
}
}
Can you please tell me what I might be doing wrong?
- Doug Witt asked 6 years ago
- You must login to post comments
I figured out my issue. I needed to set the AutoRange=”Always” on the XAxis.
- Doug Witt answered 6 years ago
- You must login to post comments
Please login first to submit.