C# wpf livechart update
- User
C# wpf livechart update
- Assistant
To update a LiveChart in C# WPF, follow these steps:
- Bind the LiveChart's SeriesCollection and Labels properties to ObservableCollection properties in your ViewModel.
<liveCharts:CartesianChart Series="{Binding SeriesCollection}"> <liveCharts:CartesianChart.AxisX> <liveCharts:Axis Title="Labels" Labels="{Binding Labels}"/> </liveCharts:CartesianChart.AxisX> <liveCharts:CartesianChart.AxisY> <liveCharts:Axis Title="Values"/> </liveCharts:CartesianChart.AxisY> </liveCharts:CartesianChart> - User
int begin_Month = begin.SelectedDate.Value.Month; int begin_year = begin.SelectedDate.Value.Year; int end_Month = end.SelectedDate.Value.Month; int end_year = end.SelectedDate.Value.Year; string[] monthNames = new string[] { "Январь ", "Февраль ", "Март ", "Апрель ", "Май ", "Июнь ", "Июль ", "Август ", "Сентябрь ", "Октябрь ", "Ноябрь ", "Декабрь ", };
- Assistant
It's difficult to determine why this code is not working without additional context or error messages. However, there are a few things that caught my attention that you might want to consider:
-
You are using an incomplete constructor for the
Pointclass. ThePoint<T, TResult>class requires two arguments: aTobject and aTResultobject. When you create a newPoint<int, int>object, you only pass in aintvalue as theBeginargument. You should consider changingnew Point<int, int>(sum, i) { }tonew Point<int, int>(sum, i). -
It looks like you are not clearing the
ChartSeriesandMonthLabelslists before adding new items to them. You might want to clear these lists before adding new items to ensure that there are no duplicates or unexpected values. -
You are using
res2.ToList()after creatingres2. This line of code does not do anything since already is a . You can remove this line of code as it is unnecessary.
-