Hello :
I adopt xamchart to display live data. I found that sometimes xamchart will show warning message as below:
index over the range. It is necessary to be positive and smaller than the size. Parameter name:index
I test my demo program that the warning message will happen almost when the program produces 200 datapoints and the warning message will happen frequently as soon as first warning message appears.
I put a xamDataGrid to show the live data at the same time to check whether it is program problem or infragistics control problem.
I found XamDataGrid is ok but XamChart is problem.
Is this a XamChart bug?
The XAML code is as below:
--------------------------------------------------------
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="ChartBugTest.Window1" x:Name="Window" Title="Window1" Width="640" Height="480" xmlns:igCA="http://infragistics.com/Chart" xmlns:igDP="http://infragistics.com/DataPresenter">
<Grid x:Name="LayoutRoot"> <igCA:XamChart Margin="136,8,192,198" x:Name="TempMeter1Chart"> <igCA:XamChart.Caption> <igCA:Caption Text="Temperature"/> </igCA:XamChart.Caption> </igCA:XamChart> <igDP:XamDataGrid AutoFit="True" Margin="136,0,192,22" VerticalAlignment="Bottom" Height="160" x:Name="DataDisplay" DataSource="{Binding Path=CurrentValue, Mode=TwoWay}" /> </Grid></Window>
---------------------------------------------------------
The code behind is as below
-------------------------------------------------------------
using System;using System.Data;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Shapes;using System.ComponentModel;using System.Timers;using System.Windows.Threading;using Infragistics.Windows.Chart;namespace ChartBugTest{ /// <summary> /// Window1.xaml 的互動邏輯 /// </summary> public partial class Window1 : Window { BoundObject bo = new BoundObject(); private Random _random = new Random(); private DispatcherTimer _timer = new DispatcherTimer(); private DataSet ds = new DataSet(); private DataTable dt = new DataTable("datatable");
private DataSet cds1 = new DataSet(); private DataTable cdt1 = new DataTable("datatable");
private Series s1 = new Series();
private string t = ""; private int ct1 = 0;
public Window1() { this.InitializeComponent(); // 在此點下方插入建立物件所需的程式碼。 StartGauge(); }
public void StartGauge() //必須判斷是否已經執行過 { if (!_timer.IsEnabled) { _timer.Interval = new TimeSpan(0, 0, 0, 0, 1500); _timer.Tick += new EventHandler(_timer_Elapsed); Loaded += new RoutedEventHandler(IAmLoaded); bo = new BoundObject { CurrentValue = 11, CurrentValue1 = 5, CurrentValue4 = 10332 }; DataContext = bo; _timer.Start();
InitialTable(); InitialChart(); InitialChartData(); } }
/// <summary> /// On load show value /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void IAmLoaded(object sender, RoutedEventArgs e) { SetValues(); }
void _timer_Elapsed(object sender, EventArgs e) { try { SetValues(); BindToChart(); BindToGrid(); } catch (Exception err) { MessageBox.Show(err.Message + "..and.. the currentvalue is:" + bo.CurrentValue); } }
/// <summary> /// Set the value and display /// </summary> private void SetValues() { int thevalue = _random.Next(40); int thewetvalue = _random.Next(10); if (thevalue >= 10) { bo.CurrentValue = thevalue; do { thewetvalue = _random.Next(10); } while (thewetvalue < 3); bo.CurrentValue1 = thevalue - thewetvalue; bo.CurrentValue2 = thevalue + 1; bo.CurrentValue3 = bo.CurrentValue2 - 3; }
int airpressure = _random.Next(10340); if (airpressure>=100) { bo.CurrentValue4 = airpressure; }
t = DateTime.Now.ToString("hh:mm:ss:tt");
} private void InitialTable() { dt.Columns.Add("count", typeof(Int32)); dt.Columns.Add("time", typeof(string)); dt.Columns.Add("temperature", typeof(Int32));
ds.Tables.Add(dt); DataDisplay.DataSource = ds.Tables["datatable"].DefaultView; } private void InitialChart() { TempMeter1Chart.Caption.Text = "Temperature Chart"; TempMeter1Chart.Visibility = Visibility.Hidden;
}
private void InitialChartData() { //---Chart1 ------------------------------- cdt1.Columns.Add("count", typeof(Int32)); cdt1.Columns.Add("temperature", typeof(Int32)); cds1.Tables.Add(cdt1);
s1.DataSource = cds1.Tables["datatable"]; s1.DataMapping = "temperature"; s1.ChartType = ChartType.Spline;
TempMeter1Chart.Axes.Clear();
Axis primAxisX1 = new Axis(); primAxisX1.AxisType = AxisType.PrimaryX; primAxisX1.AutoRange = true; TempMeter1Chart.Axes.Add(primAxisX1);
Axis primAxisY1 = new Axis(); primAxisY1.AxisType = AxisType.PrimaryY; primAxisY1.AutoRange = true; primAxisY1.Unit = 3;
TempMeter1Chart.Axes.Add(primAxisY1);
if (!TempMeter1Chart.Series.Contains(s1)) { TempMeter1Chart.Series.Add(s1); } //----- end of Chart1 -------------------
private void BindToGrid() { DataRow dr = dt.NewRow(); dr["count"] = ct1; dr["time"] = t; dr["temperature"] = bo.CurrentValue; dt.Rows.Add(dr); ds.AcceptChanges(); DataDisplay.DataItems.Insert(0,dr); }
private void BindToChart() { //--- Chart1 ----------------- DataRow dr1 = cdt1.NewRow(); dr1["count"] = ct1++;
dr1["temperature"] = bo.CurrentValue; cdt1.Rows.Add(dr1); TempMeter1Chart.RefreshEnabled = true; if (ct1 > 1) { TempMeter1Chart.Visibility = Visibility.Visible; } //---- end of chart1 --------------------------------
#region data bound class /// <summary> /// Class to do an example binding /// </summary> public class BoundObject : INotifyPropertyChanged { private double _currentValue; private double _currentValue1; private double _currentValue2; private double _currentValue3; private double _currentValue4;
/// <summary> /// Current vlaue property, raises the on property changed event /// </summary> public double CurrentValue { get { return _currentValue; } set { _currentValue = value; OnPropertyChanged("CurrentValue"); } } /// <summary> /// Current vlaue property, raises the on property changed event /// </summary> public double CurrentValue1 { get { return _currentValue1; } set { _currentValue1 = value; OnPropertyChanged("CurrentValue1"); } }
/// <summary> /// Current vlaue property, raises the on property changed event /// </summary> public double CurrentValue2 { get { return _currentValue2; } set { _currentValue2 = value; OnPropertyChanged("CurrentValue2"); } } /// <summary> /// Current vlaue property, raises the on property changed event /// </summary> public double CurrentValue3 { get { return _currentValue3; } set { _currentValue3 = value; OnPropertyChanged("CurrentValue3"); } } /// <summary> /// Current vlaue property, raises the on property changed event /// </summary> public double CurrentValue4 { get { return _currentValue4; } set { _currentValue4 = value; OnPropertyChanged("CurrentValue4"); } }
#region INotifyPropertyChanged Members
/// <summary> /// One of my properties has changed /// </summary> public event PropertyChangedEventHandler PropertyChanged;
/// <summary> /// Notify any listeners that a property has changed /// </summary> /// <param name="propName">Name of the property</param> protected virtual void OnPropertyChanged(string propName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propName)); } }
#endregion #endregion }}
---------------------------------------------------------------------------------------------------------
i was able to reproduce the problem in the latest build using your code. i have entered it as a bug, # 15099. it will be resolved in a future hotfix. feel free to contact infragistics developer support at any time (http://infragistics.com/gethelp) to inquire about the status of this bug report.
Hello:
I already update to new hotfix version 8.2.20082.2001 and it seems ok in the sample I posted but I found that the problem is still happen as soon as I put the xamChart in an usercontrol and display the usercontrol in the window. If I put xamChart in the usercontrol the trouble happened almost on 266 datapoints. Actually my ongoing project adopts 6 xamcharts in one usercontrol and that trouble condition happened on almost 100 datapoints.
I guess it was because the xamChart continuously to get the max value of primaryX to repaint itself but as the live data entering and whole dataset is large therefore xamChart could not get the necessary max value when it deceide to repain itself. Following is a simple sample of xamChart in usercontrol and trouble happens on almost 266 datapoints.
------------- window1 xaml code-------------------
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="ChartBugTest.Window1" x:Name="Window" Title="Window1" Width="640" Height="480" xmlns:igCA="http://infragistics.com/Chart" xmlns:igDP="http://infragistics.com/DataPresenter" xmlns:ChartBugTest="clr-namespace:ChartBugTest">
<Grid x:Name="LayoutRoot"> <ChartBugTest:UCChart Margin="10,10,10,10" x:Name="Chart1"/> </Grid></Window>
------------------end--------------------------
-----window1 code behind ------------------
using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Shapes;using System.ComponentModel;using System.Timers;using System.Windows.Threading;using Infragistics.Windows.Chart;namespace ChartBugTest{ /// <summary> /// Window1.xaml 的互動邏輯 /// </summary> public partial class Window1 : Window {
public Window1() { this.InitializeComponent(); // 在此點下方插入建立物件所需的程式碼。 }
}}
----------------end ---------------------------
--- UCChart.xaml usercontrol xaml code------------
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="ChartBugTest.UCChart" x:Name="UserControl" d:DesignWidth="640" d:DesignHeight="480" xmlns:igCA="http://infragistics.com/Chart" xmlns:igDP="http://infragistics.com/DataPresenter">
<Grid x:Name="LayoutRoot"> <igCA:XamChart Margin="136,8,192,198" x:Name="TempMeter1Chart"> <igCA:XamChart.Caption> <igCA:Caption Text="Temperature"/> </igCA:XamChart.Caption> </igCA:XamChart> <igDP:XamDataGrid AutoFit="True" Margin="136,0,192,22" VerticalAlignment="Bottom" Height="160" x:Name="DataDisplay" DataSource="{Binding Path=CurrentValue, Mode=TwoWay}" /> </Grid></UserControl>
-------------------end---------------------
---UCChart.xaml code behind ----------------------
using System;using System.Data;using System.Collections.Generic;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using System.ComponentModel;using System.Timers;using System.Windows.Threading;using Infragistics.Windows.Chart;namespace ChartBugTest{ /// <summary> /// UCChart.xaml 的互動邏輯 /// </summary> public partial class UCChart { BoundObject bo = new BoundObject(); private Random _random = new Random(); private DispatcherTimer _timer = new DispatcherTimer(); private DataSet ds = new DataSet(); private DataTable dt = new DataTable("datatable");
public UCChart() { this.InitializeComponent(); StartGauge(); }
/// <summary> /// On load show value /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void IAmLoaded(object sender, RoutedEventArgs e) { SetValues();
void _timer_Elapsed(object sender, EventArgs e) { try { SetValues(); BindToChart(); BindToGrid(); } catch (Exception err) { MessageBox.Show(err.Message + "..and.. the currentvalue is:" + bo.CurrentValue); }
/// <summary> /// Set the value and display /// </summary> private void SetValues() {
int thevalue = _random.Next(40); int thewetvalue = _random.Next(10); if (thevalue >= 10) { bo.CurrentValue = thevalue; do { thewetvalue = _random.Next(10); } while (thewetvalue < 3); bo.CurrentValue1 = thevalue - thewetvalue; bo.CurrentValue2 = thevalue + 1; bo.CurrentValue3 = bo.CurrentValue2 - 3; }
int airpressure = _random.Next(10340); if (airpressure >= 100) { bo.CurrentValue4 = airpressure; }
if (!TempMeter1Chart.Series.Contains(s1)) { TempMeter1Chart.Series.Add(s1); }
//----- end of Chart1 -------------------
private void BindToGrid() { DataRow dr = dt.NewRow(); dr["count"] = ct1; dr["time"] = t; dr["temperature"] = bo.CurrentValue;
dt.Rows.Add(dr); ds.AcceptChanges(); DataDisplay.DataItems.Insert(0, dr); }
private void BindToChart() {
//--- Chart1 ----------------- DataRow dr1 = cdt1.NewRow(); dr1["count"] = ct1++;
dr1["temperature"] = bo.CurrentValue; cdt1.Rows.Add(dr1); TempMeter1Chart.RefreshEnabled = true;
if (ct1 > 1) { TempMeter1Chart.Visibility = Visibility.Visible; } //---- end of chart1 --------------------------------
---------------------end ----------------------------
Hope this sample is helpful for bug resolved.
Sincerely,
Daniel Lee 2009/3/5
ok, i was able to reproduce the problem. this was reported and fixed a while back; bug report # BR33866. if you download the latest hotfix for WPF 8.2, it should be resolved.
I adopt WPF 2008V2, may be it is WPF chart 2008 v2 bug. My release build number is 8.2.20082.1002
sincerely
i was able to get the sample running using your source code, but after waiting for 250 points to appear, i didn't see any error messages using both the release build (7.2.20072.1000) and the latest source code for 7.2.
what is the complete (4-part) version number of the Infragistics dlls you're using?