Replies
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:
Server Error in '/' Application.
Index was outside the bounds of the array.
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. |
Stack Trace:
|
The BarData contains 12 items, each of which is fully initialized.
Thanks for your continued help.
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 string origData;
public int barHeight;public decimal origDataConverted;public ChartDataValue(string _origData, decimal _origDataConverted)
{
origData = _origData;
origDataConverted = _origDataConverted;
barHeight = 0;
}
}
/// <summary>
/// Custom collection
/// </summary>
public class ChartData : CollectionBase
{
/// <summary>
/// Add a new item to the collection
/// </summary>public virtual void Add(ChartDataValue toAdd)
{
this.List.Add(toAdd);
}
/// <summary>
/// Gets or sets the element at the specified index.
/// </summary>public ChartDataValue this[int index]
{
get
{
return this.List[index] as ChartDataValue;
}
}
}
public
partial class _Default : System.Web.UI.Page
{
private ChartData BarData;protected void Page_Load(object sender, EventArgs e)
{
BarData = dl.LoadData(selectedItem);
}
protected void BindingtoClassesDerivedfromCollectionBase_Load(object sender, System.EventArgs e)
{
this.UltraChart1.Data.DataSource = BarData;
UltraChart1.Data.DataBind();
}
}
(from DataLayer)
public ChartData LoadData(string practiceID)
{
// sql stuff intentionally removed here
ChartData cd = new ChartData();
string tempStr;for (int i = 0; i < 12; i++)
{
cd.Add(new ChartDataValue(GenerateMonthName(i), ParseDataValue(tempStr)));
}
return cd;
}
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