Hello,
i'm trying to add ValueOverlay to my chart programmatically, but it only works with xaml code and not code behind.
here my code:
<ig:XamDataChart Grid.Row="1" x:Name="CategoryDataChart"> <ig:XamDataChart.Axes> <ig:NumericYAxis x:Name="CategoryYAxis" IsInverted="True"/> <ig:CategoryDateTimeXAxis x:Name="CategoryXAxis" Label="{}{Date:dd/MM}" DateTimeMemberPath="Date"> <ig:CategoryDateTimeXAxis.LabelSettings> <ig:AxisLabelSettings VerticalAlignment="Bottom" HorizontalAlignment="Center" FontSize="12" Location="OutsideBottom" Extent="50" Angle="30" /> </ig:CategoryDateTimeXAxis.LabelSettings> </ig:CategoryDateTimeXAxis> </ig:XamDataChart.Axes> <ig:XamDataChart.Series> <ig:AreaSeries x:Name="series" XAxis="{Binding ElementName=CategoryXAxis}" YAxis="{Binding ElementName=CategoryYAxis}" Outline="#2db4fd" Thickness="2" TrendLineType="CubicFit" TrendLineBrush="Yellow" TrendLineDashArray="5" TrendLineThickness="3" MarkerType="None" ValueMemberPath="Value" > <ig:AreaSeries.Brush> <SolidColorBrush>#882db4fd</SolidColorBrush> </ig:AreaSeries.Brush> </ig:AreaSeries> <!--<ig:ValueOverlay Thickness="1" Title="pricedrop" Value="70" Brush="Red" DashArray="20,2" Axis="{Binding ElementName=CategoryYAxis}"> </ig:ValueOverlay>--> </ig:XamDataChart.Series> </ig:XamDataChart>
here how i'm tryng to add value dinamically:
//update itemsource CategoryDataChart.Series[0].ItemsSource = dati.Select(a => new TestDataItem { Value = a.Value, Date = ((DateTime)a.Category) }); ; ((Infragistics.Controls.Charts.CategoryDateTimeXAxis)CategoryDataChart.Axes[1]).ItemsSource = CategoryDataChart.Series[0].ItemsSource;
//adding OverlayLayer
Infragistics.Controls.Charts.ValueOverlay overlay = new Infragistics.Controls.Charts.ValueOverlay(); overlay.Axis = this.CategoryYAxis; overlay.Value = new Random().Next(60,80); overlay.Thickness = 2; overlay.Brush = new SolidColorBrush(Colors.Blue); this.CategoryDataChart.Series.Add(overlay);
thank you for any help
I'm struggling with a similar issue. Adding the DateTimeValueOverlay in code does not show anything up on the chart itself. I am building all axes and series in code, XAML chart literally looks like this (WPF):
<ig:XamDataChart x:Name="xamDataChart" CrosshairVisibility="Visible" HorizontalZoomable="True" VerticalZoomable="True" ToolTipStyle="{StaticResource ToolTipStyle}" />
The adding of the DateTimeValueOverlay goes like this, after all axes and series have been added to the chart programmatically:
// add data date line if required if (this.ChartDefinition.DataDate != null && dataDateLine == null) { Infragistics.Controls.Charts.CategoryDateTimeXAxis xAxis = xamDataChart.Axes .Where(a => a is Infragistics.Controls.Charts.CategoryDateTimeXAxis) .Select(a => (Infragistics.Controls.Charts.CategoryDateTimeXAxis)a).FirstOrDefault(); if (xAxis != null) { // set the data date if it is supposed to be today if (this.ChartDefinition.DataDateUseToday == true) this.ChartDefinition.DataDate = DateTime.Today; // get the chart context (data) for this series System.Collections.Generic.List<ChartDataPoint> seriesContext = xAxis.ItemsSource as System.Collections.Generic.List<ChartDataPoint>; // match the date up to the corresponding data point var dataDateOverlayValue = seriesContext .Where(c => this.ChartDefinition.DataDate.HasValue == true && c.AxisXValue != null && c.AxisXValue is DateTime && (DateTime)c.AxisXValue < this.ChartDefinition.DataDate.Value) .Select(c => (DateTime)c.AxisXValue) .OrderByDescending(c => c) .FirstOrDefault(); // build the series dataDateLine = new Infragistics.Controls.Charts.DateTimeValueOverlay(); dataDateLine.Opacity = 1d; dataDateLine.Brush = System.Windows.Media.Brushes.Yellow; dataDateLine.Thickness = 2d; dataDateLine.LegendItemVisibility = System.Windows.Visibility.Collapsed; dataDateLine.Axis = xAxis; dataDateLine.ItemsSource = seriesContext; dataDateLine.Title = "Data Date"; dataDateLine.Value = dataDateOverlayValue; // add it to the chart xamDataChart.Series.Add(dataDateLine); }}
// add data date line if required if (this.ChartDefinition.DataDate != null && dataDateLine == null) { Infragistics.Controls.Charts.CategoryDateTimeXAxis xAxis = xamDataChart.Axes .Where(a => a is Infragistics.Controls.Charts.CategoryDateTimeXAxis) .Select(a => (Infragistics.Controls.Charts.CategoryDateTimeXAxis)a).FirstOrDefault();
if (xAxis != null) { // set the data date if it is supposed to be today if (this.ChartDefinition.DataDateUseToday == true) this.ChartDefinition.DataDate = DateTime.Today;
// get the chart context (data) for this series System.Collections.Generic.List<ChartDataPoint> seriesContext = xAxis.ItemsSource as System.Collections.Generic.List<ChartDataPoint>;
// match the date up to the corresponding data point var dataDateOverlayValue = seriesContext .Where(c => this.ChartDefinition.DataDate.HasValue == true && c.AxisXValue != null && c.AxisXValue is DateTime && (DateTime)c.AxisXValue < this.ChartDefinition.DataDate.Value) .Select(c => (DateTime)c.AxisXValue) .OrderByDescending(c => c) .FirstOrDefault();
// build the series dataDateLine = new Infragistics.Controls.Charts.DateTimeValueOverlay(); dataDateLine.Opacity = 1d; dataDateLine.Brush = System.Windows.Media.Brushes.Yellow; dataDateLine.Thickness = 2d; dataDateLine.LegendItemVisibility = System.Windows.Visibility.Collapsed; dataDateLine.Axis = xAxis; dataDateLine.ItemsSource = seriesContext; dataDateLine.Title = "Data Date"; dataDateLine.Value = dataDateOverlayValue; // add it to the chart xamDataChart.Series.Add(dataDateLine); }}
Axis is found and set correctly, as is dataDateOverlayValue.
Any help would be appreciated, thank you!
Hello Riccardo,
Thank you for your email. I am very glad that you have managed to solve the issue that you were having. Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir, MCPD
Developer Support Supervisor - XAML
Infragistics
www.infragistics.com/support
solved i've to import also the default syle
Hello Krasimir,
thank you it's finally working :)
anyway i'm trying to add the valueOverlay to a datetime axis:
i'm using the calss found here DateTimeValueOverlay:
http://ko.infragistics.com/community/forums/p/75441/381189.aspx
Infragistics.Controls.Charts.DateTimeValueOverlay overlay = new Infragistics.Controls.Charts.DateTimeValueOverlay(); overlay.ItemsSource = CategoryDataChart.Series[0].ItemsSource; overlay.Axis = ( Infragistics.Controls.Charts.CategoryAxisBase)CategoryDataChart.Axes[1]; overlay.Value = DateTime.Now.Date.AddDays(-5); overlay.Thickness = 2; overlay.Brush = new SolidColorBrush(Colors.Blue); this.CategoryDataChart.Series.Add(overlay);
and again nothing is showed
do you kow why?
thank you
Thank you for your email. I have been looking into the question that you are having and the reason for the ValueOverlay to not being displayed is that this.CategoryYAxis is retuning null in the code behind. .The reason for this.CategoryYAxis to be null is that, if you have an element that is part of a collection (as the axis in Axes collection of the XamDataChart and also the columns in the Columns collection of the XamGrid) and you set the x:Key attribute to this element, in the code-behind, if you access the element by name, it is null. This seems to be a limitation in the Silverlight, that Stoimen has described in this thread: http://ko.infragistics.com/community/forums/t/53154.aspx.
In order to be able to set the axis, you can use the Axes collection of the XamDataChart as follow:
overlay.Axis = CategoryDataChart.Axes[0] as NumericYAxis;
I have created a sample application for you, that shows how you can add the ValueOverlay in code.
Please let me know if you need any further assistance on the matter.