How to: Bind a Range Filter Dashboard Item to Data in Code
- 3 minutes to read
using DevExpress.DashboardCommon;
using System;
// ...
private RangeFilterDashboardItem CreateRangeFilter(IDashboardDataSource dataSource)
{
// Create a Range Filter dashboard item and specify its data source.
RangeFilterDashboardItem rangeFilter = new RangeFilterDashboardItem();
rangeFilter.DataSource = dataSource;
// Create a new series of the Area type and add this series to the Series collection to
// display it within the Range Filter.
SimpleSeries salesAmountSeries = new SimpleSeries(SimpleSeriesType.Area);
rangeFilter.Series.Add(salesAmountSeries);
// Specify a measure to provide data used to calculate the Y-coordinate of the data points.
salesAmountSeries.Value = new Measure("Extended Price");
// Specify a dimension to provide Range Filter argument values.
rangeFilter.Argument = new Dimension("OrderDate");
// Specify a group interval for argument values.
rangeFilter.Argument.DateTimeGroupInterval = DateTimeGroupInterval.MonthYear;
// Restrict the displayed data.
rangeFilter.FilterString = "[OrderDate] > #2018-01-01#";
// Add predefined ranges to the context menu.
// You can show the item caption and use the Select Date Time Periods drop-down button to apply predefined ranges.
rangeFilter.DateTimePeriods.AddRange(
DateTimePeriod.CreateLastYear(),
DateTimePeriod.CreateNextMonths("Next 3 Months", 3),
new DateTimePeriod
{ Name = "Year To Date",
Start = new FlowDateTimePeriodLimit(DateTimeInterval.Year, 0),
End = new FlowDateTimePeriodLimit(DateTimeInterval.Day, 1)
},
new DateTimePeriod
{ Name = "Jul-18-2018 - Jan-18-2019",
Start = new FixedDateTimePeriodLimit(new DateTime(2018, 7, 18)),
End = new FixedDateTimePeriodLimit(new DateTime(2019, 1, 18)) }
);
// Specify the period selected when the control is initialized.
rangeFilter.DefaultDateTimePeriodName = "Year To Date";
// The caption is initially hidden. Uncomment the line to show the caption.
//rangeFilter.ShowCaption = true;
return rangeFilter;
}
See Also