What am I doing wrong?
DataTable dt = new DataTable(); dt.Columns.Add("Value"); dt.Columns.Add("Date"); DataRow row = dt.NewRow(); row[0] = "2"; row[1] = DateTime.Today.AddDays(-1); dt.Rows.Add(row); row = dt.NewRow(); row[0] = "3"; row[1] = DateTime.Today.AddDays(-2); dt.Rows.Add(row); row = dt.NewRow(); row[0] = "4"; row[1] = DateTime.Today.AddDays(-3); dt.Rows.Add(row); myChart.DataSource = dt; myChart.DataBind();
Also tried this with NumericSeries per an example I found and I am receiving the same error. What gives?
This is likely to happen when you don't specify the column type. Try using dt.Columns.Add("Value", typeof(int));dt.Columns.Add("Date", typeof(DateTime));Also, in order for the line chart to display a date time axis, you need to setchart.LineChart.TreatDateTimeAsString = false;https://ko.infragistics.com/help/aspnet/chart-display-data-on-a-time-scale-axis
I'm getting this same error, when I use a Bar Chart and it is bound to a Collection derived from CollectionBase.
Here's my code:
public class ChartDataValue
{
public int barHeight;
origData = _origData;
origDataConverted = _origDataConverted;
barHeight = 0;
}
/// <summary>
/// Custom collection
/// </summary>
public class ChartData : CollectionBase
/// Add a new item to the collection
/// Gets or sets the element at the specified index.
get
public partial class _Default : System.Web.UI.Page
BarData = dl.LoadData(selectedItem);
UltraChart1.Data.DataBind();
(from DataLayer)
// sql stuff intentionally removed here
string tempStr;
I have checked this with a breakpoint at runtime, and just before the call to DataBind(), my ChartData Collection contains 12 items, each of class ChartDataValue. Inside each ChartDataValue, as expected, the MonthName appears in the origData, and the decimal value is in origDataConverted.
All requirements in the documentation seem to be fulfilled, however it still just draws the red error message saying:
You must have at least one row and one numeric column
the chart uses the public properties (not fields) on your data objects to determine the item labels and data values. add these lines to your ChartDataValue class and both CollectionBase and List<T> scenarios should work fine.
public decimal OrigDataConverted { get { return this.origDataConverted; } } public string OrigData { get { return this.origData; } }
I was just following the docs, and they say to derive from CollectionBase.
OK, so I tried using List<ChartDataValue> and I think I'm getting closer.
I get a different error message now:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
[IndexOutOfRangeException: Index was outside the bounds of the array.] Infragistics.UltraChart.Data.IListToChartAdapter2.GetObjectValue(Int32 row, Int32 column) +70 Infragistics.UltraChart.Data.IListToChartAdapter2.IsColumnString(Int32 column) +34 Infragistics.UltraChart.Core.Layers.Layer.SetupDataFilter(DataAppearance dataApp) +216 Infragistics.UltraChart.Core.Layers.Layer.SetupDataFilter() +73 Infragistics.UltraChart.Core.Layers.ChartLayer.SetData(IChartData data) +52 Infragistics.UltraChart.Core.ChartCore.SetDataIntoLayers(IChartData data) +116 Infragistics.UltraChart.Core.ChartCore.SetupDataModel() +2008 Infragistics.UltraChart.Core.ChartCore.DrawChart() +161 Infragistics.WebUI.UltraWebChart.UltraChart.Render(HtmlTextWriter output) +16552 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
The BarData contains 12 items, each of which is fully initialized.
Thanks for your continued help.
What happens if you use a List<ChartDataValue>, as opposed to a custom collection?