Chart - view model get data from outside

2 Answers 133 Views
Chart DatePicker TimePicker
Daniel
Top achievements
Rank 1
Silver
Bronze
Daniel asked on 10 Mar 2022, 08:05 AM

Hi,

I have two RadDateTimePickers and search button I want when I click on button the data on 

chart need to  be updated.

How I pass datetime picker selection to view model or there is other simple way?

Thanks,

 <telerikChart:RadCartesianChart Grid.Row="4" Grid.Column="0">

                <telerikChart:RadCartesianChart.BindingContext>
                    <local:TotalFilesDividedByRoutesDataViewModel />
                </telerikChart:RadCartesianChart.BindingContext>
                <telerikChart:RadCartesianChart.HorizontalAxis>
                    <telerikChart:CategoricalAxis PlotMode="OnTicks"
                                    MajorTickInterval="2"
                                    GapLength="0.5"/>
                </telerikChart:RadCartesianChart.HorizontalAxis>
                <telerikChart:RadCartesianChart.VerticalAxis>
                    <telerikChart:NumericalAxis LabelFitMode="MultiLine" />
                </telerikChart:RadCartesianChart.VerticalAxis>
                <telerikChart:RadCartesianChart.Series>
                    <telerikChart:BarSeries ValueBinding="Value"
                                    CategoryBinding="RouteName"
                                    ItemsSource="{Binding Data}" />
                </telerikChart:RadCartesianChart.Series>
            </telerikChart:RadCartesianChart>

2 Answers, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 11 Mar 2022, 09:09 AM

Hi Daniel,

I assume you are using DatePicker control. In order to get the selected date, you have to use the Date property. Here are all properties described for the DatPicker Selection https://docs.telerik.com/devtools/maui/controls/datepicker/datepicker-selection The property is bindable property.

Regards,
Didi
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Daniel
Top achievements
Rank 1
Silver
Bronze
answered on 11 Mar 2022, 09:56 AM
can you give sniped code how is bindable date property to view model?
Didi
Telerik team
commented on 11 Mar 2022, 12:32 PM | edited

Here is a sample code: 

            <telerikInput:RadDatePicker Date="{Binding Date, Mode=TwoWay}"/>

ViewModel:

public class ViewModel : INotifyPropertyChanged
{
    private DateTime? date;
    public ViewModel()
    {
        this.Date = DateTime.Now;
    }
    public DateTime? Date
    {
        get
        {
            return date;
        }
        set
        {
            if (date != value)
            {
                date = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Date"));
            }
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;
}

 

General Data Binding information:

More details about data bindings can be found in the official .NET MAUI documentation: https://docs.microsoft.com/en-us/dotnet/maui/xaml/fundamentals/data-binding-basics 
I suggest you review all articles inside the Fundamentals section of the .NET MAUI documentation.

Tags
Chart DatePicker TimePicker
Asked by
Daniel
Top achievements
Rank 1
Silver
Bronze
Answers by
Didi
Telerik team
Daniel
Top achievements
Rank 1
Silver
Bronze
Share this question
or