Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.
The Chart Control can generate its child elements from their ViewModels. This is useful when the application uses the MVVM architecture and the Chart should contain several chart elements that are bound to data.
You can bind the element’s ItemsSource to the View Model’s property to generate a chart element collection from a chart’s View Model. Then specify the element’s ItemTemplate or ItemTemplateSelector to bind the element’s properties to the element view model’s properties. For example, you can bind a chart’s legend collection to the view model’s legend collection using the ChartControlBase.LegendItemsSource and configure the generated legends using the ChartControlBase.LegendItemTemplate.
ImportsSystemImportsSystem.Collections.GenericImportsSystem.Collections.ObjectModelImportsSystem.GlobalizationImportsSystem.IOImportsSystem.Xml.LinqNamespace MvvmSample.Model
FriendClass WeatherInfo
Private privateTimestamp AsDatePublicProperty Timestamp() AsDateGetReturn privateTimestamp
EndGetPrivateSet(ByVal value AsDate)
privateTimestamp = value
EndSetEndPropertyPrivate privateTemperature AsDoublePublicProperty Temperature() AsDoubleGetReturn privateTemperature
EndGetPrivateSet(ByVal value AsDouble)
privateTemperature = value
EndSetEndPropertyPrivate privatePressure AsIntegerPublicProperty Pressure() AsIntegerGetReturn privatePressure
EndGetPrivateSet(ByVal value AsInteger)
privatePressure = value
EndSetEndPropertyPrivate privateRelativeHumidity AsIntegerPublicProperty RelativeHumidity() AsIntegerGetReturn privateRelativeHumidity
EndGetPrivateSet(ByVal value AsInteger)
privateRelativeHumidity = value
EndSetEndPropertyPublicSubNew(ByVal timestamp AsDate, ByVal temperature AsDouble, ByVal pressure AsInteger, ByVal relativeHumidity AsInteger)
Me.Timestamp = timestamp
Me.Temperature = temperature
Me.Pressure = pressure
Me.RelativeHumidity = relativeHumidity
EndSubEndClassFriendInterface WeatherProvider
ReadOnlyProperty WeatherInfos() As IEnumerable(Of WeatherInfo)
EndInterfaceFriendClass XmlWeatherProvider
Implements WeatherProvider
Private filename AsStringPublicSubNew(ByVal filename AsString)
If File.Exists(filename) ThenMe.filename = filename
ElseThrowNew Exception(String.Format("The '{0}' file does not exist.", filename))
EndIfEndSubPrivate infos As Collection(Of WeatherInfo)
PublicReadOnlyProperty WeatherInfos() As IEnumerable(Of WeatherInfo) Implements WeatherProvider.WeatherInfos
GetIf infos IsNothingThenDim doc As XDocument = XDocument.Load(filename)
infos = New Collection(Of WeatherInfo)()
ForEach element As XElement In doc.Element("WeatherData").Elements("WeatherInfo")
infos.Add(New WeatherInfo(timestamp:= Date.Parse(element.Element("Timestamp").Value, CultureInfo.InvariantCulture), temperature:= Double.Parse(element.Element("Temperature").Value, CultureInfo.InvariantCulture), pressure:= Integer.Parse(element.Element("Pressure").Value, CultureInfo.InvariantCulture), relativeHumidity:= Integer.Parse(element.Element("RelativeHumidity").Value, CultureInfo.InvariantCulture)))
Next element
EndIfReturn infos
EndGetEndPropertyEndClassEndNamespace
Imports MvvmSample.ViewModel
ImportsSystemImportsSystem.Collections.GenericImportsSystem.LinqImports System.TextImportsSystem.Threading.TasksImportsSystem.WindowsImportsSystem.Windows.ControlsImportsSystem.Windows.DataImportsSystem.Windows.DocumentsImportsSystem.Windows.InputImportsSystem.Windows.MediaImportsSystem.Windows.Media.ImagingImportsSystem.Windows.NavigationImportsSystem.Windows.ShapesNamespace MvvmSample
'''<summary>''' Interaction logic for MainWindow.xaml'''</summary>PartialPublicClass MainWindow
Inherits Window
PublicSubNew()
InitializeComponent()
EndSubEndClassPublicClass SeriesTypeTemplateSelector
Inherits DataTemplateSelector
PublicProperty AreaTemplate() As DataTemplate
PublicProperty BarTemplate() As DataTemplate
PublicProperty LineTemplate() As DataTemplate
PublicOverridesFunction SelectTemplate(ByVal item AsObject, ByVal container As DependencyObject) As DataTemplate
Dim seriesVM As SeriesViewModel = TryCast(item, SeriesViewModel)
If seriesVM IsNothingThenReturnMyBase.SelectTemplate(item, container)
EndIfSelectCase seriesVM.Type
Case SeriesType.Area
Return AreaTemplate
Case SeriesType.Bar
Return BarTemplate
Case SeriesType.Line
Return LineTemplate
CaseElseReturnMyBase.SelectTemplate(item, container)
EndSelectEndFunctionEndClassEndNamespace
ImportsSystemImportsSystem.Collections.GenericImportsSystem.LinqImports System.TextImportsSystem.Threading.TasksNamespace MvvmSample.ViewModel
FriendClass ChartViewModel
Private privatePanes As IEnumerable(Of PaneViewModel)
PublicProperty Panes() As IEnumerable(Of PaneViewModel)
GetReturn privatePanes
EndGetPrivateSet(ByVal value As IEnumerable(Of PaneViewModel))
privatePanes = value
EndSetEndPropertyPrivate privateXAxis As XAxisViewModel
PublicProperty XAxis() As XAxisViewModel
GetReturn privateXAxis
EndGetPrivateSet(ByVal value As XAxisViewModel)
privateXAxis = value
EndSetEndPropertyPrivate privateYAxes As IEnumerable(Of YAxisViewModel)
PublicProperty YAxes() As IEnumerable(Of YAxisViewModel)
GetReturn privateYAxes
EndGetPrivateSet(ByVal value As IEnumerable(Of YAxisViewModel))
privateYAxes = value
EndSetEndPropertyPrivate privateSeries As IEnumerable(Of SeriesViewModel)
PublicProperty Series() As IEnumerable(Of SeriesViewModel)
GetReturn privateSeries
EndGetPrivateSet(ByVal value As IEnumerable(Of SeriesViewModel))
privateSeries = value
EndSetEndPropertyPrivate privateLegends As IEnumerable(Of LegendViewModel)
PublicProperty Legends() As IEnumerable(Of LegendViewModel)
GetReturn privateLegends
EndGetPrivateSet(ByVal value As IEnumerable(Of LegendViewModel))
privateLegends = value
EndSetEndPropertyPublicSubNew(ByVal series As IEnumerable(Of SeriesViewModel), ByVal legends As IEnumerable(Of LegendViewModel), ByVal panes As IEnumerable(Of PaneViewModel), ByVal xAxis As XAxisViewModel, ByVal yAxes As IEnumerable(Of YAxisViewModel))
Me.Series = series
Me.XAxis = xAxis
Me.YAxes = yAxes
Me.Panes = panes
Me.Legends = legends
EndSubEndClassFriendClass LegendViewModel
Private privateDockTarget As PaneViewModel
PublicProperty DockTarget() As PaneViewModel
GetReturn privateDockTarget
EndGetPrivateSet(ByVal value As PaneViewModel)
privateDockTarget = value
EndSetEndPropertyPublicSubNew(ByVal dockTarget As PaneViewModel)
Me.DockTarget = dockTarget
EndSubEndClassFriendClass PaneViewModel
Private privateShowXAxis AsBooleanPublicProperty ShowXAxis() AsBooleanGetReturn privateShowXAxis
EndGetPrivateSet(ByVal value AsBoolean)
privateShowXAxis = value
EndSetEndPropertyPublicSubNew(ByVal showXAxis AsBoolean)
Me.ShowXAxis = showXAxis
EndSubEndClassFriendClass XAxisViewModel
PublicProperty MinValue() AsDatePublicProperty MaxValue() AsDateEndClassFriendClass YAxisViewModel
Private privateTitle AsStringPublicProperty Title() AsStringGetReturn privateTitle
EndGetPrivateSet(ByVal value AsString)
privateTitle = value
EndSetEndPropertyPrivate privateConstantLines As IEnumerable(Of ConstantLineViewModel)
PublicProperty ConstantLines() As IEnumerable(Of ConstantLineViewModel)
GetReturn privateConstantLines
EndGetPrivateSet(ByVal value As IEnumerable(Of ConstantLineViewModel))
privateConstantLines = value
EndSetEndPropertyPublicSubNew(ByVal title AsString, ByVal constantLines As IEnumerable(Of ConstantLineViewModel))
Me.Title = title
Me.ConstantLines = constantLines
EndSubEndClassFriendClass SeriesViewModel
PublicProperty Name() AsStringPrivate privateArgumentName AsStringPublicProperty ArgumentName() AsStringGetReturn privateArgumentName
EndGetPrivateSet(ByVal value AsString)
privateArgumentName = value
EndSetEndPropertyPrivate privateValueName AsStringPublicProperty ValueName() AsStringGetReturn privateValueName
EndGetPrivateSet(ByVal value AsString)
privateValueName = value
EndSetEndPropertyPrivate privateLegend As LegendViewModel
PublicProperty Legend() As LegendViewModel
GetReturn privateLegend
EndGetPrivateSet(ByVal value As LegendViewModel)
privateLegend = value
EndSetEndPropertyPrivate privatePane As PaneViewModel
PublicProperty Pane() As PaneViewModel
GetReturn privatePane
EndGetPrivateSet(ByVal value As PaneViewModel)
privatePane = value
EndSetEndPropertyPrivate privateYAxis As YAxisViewModel
PublicProperty YAxis() As YAxisViewModel
GetReturn privateYAxis
EndGetPrivateSet(ByVal value As YAxisViewModel)
privateYAxis = value
EndSetEndPropertyPrivate privateType As SeriesType
PublicProperty Type() As SeriesType
GetReturn privateType
EndGetPrivateSet(ByVal value As SeriesType)
privateType = value
EndSetEndPropertyPublicSubNew(ByVal name AsString, ByVal type As SeriesType, ByVal argumentName AsString, ByVal valueName AsString, ByVal legend As LegendViewModel, ByVal pane As PaneViewModel, ByVal yAxis As YAxisViewModel)
Me.Name = name
Me.Type = type
Me.ArgumentName = argumentName
Me.ValueName = valueName
Me.Legend = legend
Me.Pane = pane
Me.YAxis = yAxis
EndSubEndClassFriendClass ConstantLineViewModel
Private privateTitle AsStringPublicProperty Title() AsStringGetReturn privateTitle
EndGetPrivateSet(ByVal value AsString)
privateTitle = value
EndSetEndPropertyPrivate privateValue AsDoublePublicProperty Value() AsDoubleGetReturn privateValue
EndGetPrivateSet(ByVal value AsDouble)
privateValue = value
EndSetEndPropertyPublicSubNew(ByVal title AsString, ByVal value AsDouble)
Me.Title = title
Me.Value = value
EndSubEndClassPublicEnum SeriesType
Bar
Area
Line
EndEnumEndNamespace
Imports MvvmSample.Model
ImportsSystemImportsSystem.LinqNamespace MvvmSample.ViewModel
FriendClass MainViewModel
Private privateChart As ChartViewModel
PublicProperty Chart() As ChartViewModel
GetReturn privateChart
EndGetPrivateSet(ByVal value As ChartViewModel)
privateChart = value
EndSetEndPropertyPrivate privateDataProvider As WeatherProvider
PublicProperty DataProvider() As WeatherProvider
GetReturn privateDataProvider
EndGetPrivateSet(ByVal value As WeatherProvider)
privateDataProvider = value
EndSetEndPropertyPublicSubNew()
DataProvider = New XmlWeatherProvider("Data/WeatherData.xml")
Dim temperaturePane AsNew PaneViewModel(showXAxis:= False)
Dim pressurePane AsNew PaneViewModel(showXAxis:= False)
Dim humidityPane AsNew PaneViewModel(showXAxis:= True)
Dim temperatureLegend AsNew LegendViewModel(dockTarget:= temperaturePane)
Dim pressureLegend AsNew LegendViewModel(dockTarget:= pressurePane)
Dim humidityLegend AsNew LegendViewModel(dockTarget:= humidityPane)
Dim xAxis As XAxisViewModel = New XAxisViewModel With { _
.MinValue = DataProvider.WeatherInfos.First().Timestamp, _
.MaxValue = DataProvider.WeatherInfos.ElementAt(10).Timestamp _
}
Dim temperatureYAxis AsNew YAxisViewModel(title:= "Temperature, F", constantLines:= Nothing)
Dim pressureYAxis AsNew YAxisViewModel(title:= "Pressure, mbar", constantLines:= Nothing)
Dim humidityYAxis AsNew YAxisViewModel(title:= "Humidity, %", constantLines:= New ConstantLineViewModel() { New ConstantLineViewModel(title:= String.Empty, value:= 60.0) })
Dim temperatureSeries AsNew SeriesViewModel(name:= "Temperature", type:= SeriesType.Line, argumentName:= "Timestamp", valueName:= "Temperature", legend:= temperatureLegend, pane:= temperaturePane, yAxis:= temperatureYAxis)
Dim pressureSeries AsNew SeriesViewModel(name:= "Pressure", type:= SeriesType.Area, argumentName:= "Timestamp", valueName:= "Pressure", legend:= pressureLegend, pane:= pressurePane, yAxis:= pressureYAxis)
Dim humiditySeries AsNew SeriesViewModel(name:= "Humidity", type:= SeriesType.Bar, argumentName:= "Timestamp", valueName:= "RelativeHumidity", legend:= humidityLegend, pane:= humidityPane, yAxis:= humidityYAxis)
Chart = New ChartViewModel(series:= New SeriesViewModel() { temperatureSeries, pressureSeries, humiditySeries }, panes:= New PaneViewModel() { temperaturePane, pressurePane, humidityPane }, xAxis:= xAxis, yAxes:= New YAxisViewModel() { temperatureYAxis, pressureYAxis, humidityYAxis }, legends:= New LegendViewModel() { temperatureLegend, pressureLegend, humidityLegend })
EndSubEndClassEndNamespace
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SeriesItemsSource property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.