The samples that come with the 10.2 DV product do not have any samples on dynamically adding anything and all my CTP code is completely different. Does anyone have a sample of dynamically adding a few series to a data chart? I am obviously missing something as I continuously get an error of value out of range but no details as to what value. My code does not throw any error, it simply gets caught in the app_unhandledexception.
What I have done is try to add items that will not change in the xaml and then dynamically add the series.
<igCtrls:XamDock x:Name="XamDataChartContainer" Margin="0"> <Border Style="{StaticResource BorderStyle}"> <Border.Effect> <DropShadowEffect Color="Black" BlurRadius="10" ShadowDepth="0" Opacity="0.7"></DropShadowEffect> </Border.Effect> </Border> <igChart:XamDataChart x:Name="xmDataChart" Margin="0" Height="300"> <igChart:XamDataChart.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF435053" Offset="0"/> <GradientStop Color="#FF404D50" Offset="1"/> </LinearGradientBrush> </igChart:XamDataChart.Background> <igChart:XamDataChart.Axes> <igChart:CategoryXAxis x:Name="XAxis" Style="{StaticResource CategoryXAxisStyle}" ItemsSource="{Binding}" Label="{}{TimeStamp:M/d HH:mm}"> <igChart:CategoryXAxis.LabelSettings> <igChart:AxisLabelSettings Location="OutsideBottom" Visibility="Visible" /> </igChart:CategoryXAxis.LabelSettings> </igChart:CategoryXAxis> </igChart:XamDataChart.Axes> <igChart:XamDataChart.Series> <!-- Dynamically add in the series --> </igChart:XamDataChart.Series>
</igChart:XamDataChart> <igChart:Legend x:Name="xmLegendOTC" Content="Legend" igCtrls:XamDock.Edge="OutsideLeft" igCtrls:XamDock.HorizontalDockAlignment="Left" igCtrls:XamDock.VerticalDockAlignment="Top" Style="{StaticResource LegendStyle}"> </igChart:Legend> <StackPanel Orientation="Vertical" igCtrls:XamDock.Edge="OutsideLeft" igCtrls:XamDock.VerticalDockAlignment="Bottom" Margin="0,0,0,0" > <Button x:Name="btnHistory" Click="btnHistory_Click" Width="32" Height="32" Style="{StaticResource customButtonStyle}" Margin="19,5" ToolTipService.ToolTip="Show History"> <Image Source="images/clock_play.png" Stretch="None" RenderTransformOrigin="0.5,0.5" /> </Button> <Button x:Name="btnPrint" Click="btnPrint_Click" Width="32" Height="32" Style="{StaticResource customButtonStyle}" Margin="19,5" ToolTipService.ToolTip="Print"> <Image Source="images/printer.png" Stretch="None" RenderTransformOrigin="0.5,0.5" /> </Button> </StackPanel> </igCtrls:XamDock>
*** code behind ***string channelName = "test series";
// create new Y axisNumericYAxis yaxis = new NumericYAxis();yaxis.Visibility = System.Windows.Visibility.Collapsed;yaxis.Name = channelName;xmDataChart.Axes.Add(yaxis);
StepLineSeries series = new StepLineSeries();series.Title = channelName;series.ValueMemberPath = "Value";series.XAxis = xmDataChart.Axes["XAxis"] as CategoryXAxis;//series.XAxis.Label = "{TimeStamp:HH:mm}";series.YAxis = yaxis;
I have left some linkage off somewhere but I am unsure how to mixed the static and dynamic content into the same datachart.
Looks like you were just missing assigning ItemsSource property of the series and adding the series to the collection:StepLineSeries series = new StepLineSeries();series.XAxis = xmDataChart.Axes["XAxis"] as CategoryXAxis;series.YAxis = yaxis;series.ItemsSource = yourDataSource;series.ValueMemberPath = "Value";xmDataChart.Series.Add(series);
Actually I didn't proofread my post. I actually left off those 2 lines. Apparently the problem I ran into was I also needed to set the ItemSource property of the xAxis.
StepLineSeries series = new StepLineSeries();series.Title = channelName;series.ValueMemberPath = "Value";series.XAxis = xmDataChart.Axes["XAxis"] as CategoryXAxis;series.XAxis.ItemsSource = historicalData.First(d => d.index == channelIndex).ChannelDataList;series.YAxis = yaxis; //xmDataChart.Axes["xmYAxis"] as NumericYAxis;series.ItemsSource = series.XAxis.ItemsSource;xmDataChart.Series.Add(series);
If I am going to be adding several series to a data chart all of which will share the same xaxis (time based) but have independent yaxis how whould you recommend I set that up? Should I reset the itemsource of the xaxis each time, set it one time or add a new one with each series?
If you're using the same x axis for your series, it's sufficient to have a binding set once in xaml or in code. Then, set the XAxis property on each new seris to the existing X axis. Each new series also needs to have its ItemsSource property set. That should be enough.
Let me add a little more detail and see if that changes anything as I am not sure what I would bind the x axis to yet.
The chart will be receiving data points continuously containing various device data from serveral sources (such as oxygen levels, blood concentration, flow rates, etc). So each time a point comes in I have to check to see what it is and either add it to an existing queue or create a new queue, bind it to a new series and add the series to the chart. Each queue will have its own collection of datetime/value pairs but the datetime range will be consistent across all queues. Given that, how would all the series share the same x axis? What would I bind the x axis to?
If you intend to use multiple sources for the x axes, then you will not be able to share them. However, in your scenario, you should be able to only bind the x axis to one of the sources, since the date range is consistent across all series. Try setting xAxis.ItemsSource to one of your queues and referencing that axis is each series. I believe this will work for you.