WPF DateTimeAxis Number Tracing?

advertisements

I created a graph with column series by using data visualization and in that i've taken DateTimeAxis as x-axis and i've one combo box with time intervals and based on selection of combo box i need to bind intervals into my graph at runtime. The problem is i'm getting error if i select intervals randomly like

var xAxis = countChart.ActualAxes.OfType<DateTimeAxis>().FirstOrDefault(ax => ax.Orientation == AxisOrientation.X);
xAxis.Minimum = DateTime.Parse(fromDt.ToString("HH:mm:ss"));
xAxis.Maximum = DateTime.Parse(toDt.ToString("HH:mm:ss"));

"The minimum value must be smaller than or equal to the maximum value."

so how can i overcome my problem plz help me.

Thanks, @Nagaraju.


Check and modify the Minimum and Maximum properties as needed.

Don't use fallback values in binding, but control the dates set by yourself. If you're not using view model, you could use the setter logics in code-behind.

<charting:DateTimeAxis
    Orientation="X"
    IntervalType="{Binding IntervalType, FallbackValue=Years}"
    Interval="{Binding Interval}"
    Maximum="{Binding EndDate}"
    Minimum="{Binding StartDate}" />

public DateTime StartDate
{
    get { return _startDate; }
    set
    {
        if (EndDate < value)
        {
            EndDate = value;
        }

        // Set property and notify that property has changed
        //...
    }
}

private DateTime _endDate;
public DateTime EndDate
{
    get { return _endDate; }
    set
    {
        if (StartDate > value)
        {
           StartDate = value;
        }

        // Set property and notify that property has changed
        //...
    }
}