我有以下abstract
课程:
public abstract class ChartHelper
{
public System.Windows.Forms.DataVisualization.Charting.Chart resultChart { get; set; }
public String TimeType { get; set; }
protected List<IObject> _datalist;
protected TimeType _timeType;
protected DateTime _stopDate;
protected DateTime _startDate;
protected void SetXAsisTime()
{
if (resultChart != null)
{
foreach (var series in resultChart.Series)
{
series.XValueType = _timeType != DateUtils.TimeType.Weeks ? ChartValueType.DateTime : ChartValueType.String;
}
resultChart.ChartAreas[0].AxisX.LabelStyle.Format = GetLabelFormat();
resultChart.ChartAreas[0].AxisX.Interval = 1;
resultChart.ChartAreas[0].AxisX.IntervalType = GetIntervalType();
resultChart.ChartAreas[0].AxisX.IntervalOffset = 1;
}
}
protected String GetLabelFormat()
{
switch (_timeType)
{
case DateUtils.TimeType.Weeks:
return "Uge:";
case DateUtils.TimeType.Months:
return "MM";
case DateUtils.TimeType.Years:
return "YYYY";
default:
return "DD";
}
}
现在,当我尝试设置AxisX标签格式时: resultChart.ChartAreas[0].AxisX.LabelStyle.Format = GetLabelFormat();
我收到以下错误消息:
System.ArgumentOutOfRangeException was unhandled
Message=Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Source=mscorlib
ParamName=index
StackTrace:
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at System.Collections.ObjectModel.Collection`1.get_Item(Int32 index)
at Henvendelser.Chart.ChartHelper.SetXAsisTime()
at Henvendelser.Chart.EmailChartGenerator.GetChart()
at Henvendelser.Models.EmailModel.GetEmailChart(DateTime start, DateTime end, TimeType timeType)
at Henvendelser.Main.SetHenvendelserData(DateTime from, DateTime to)
at Henvendelser.Main.btn_getData_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Henvendelser.Program.Main()
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
有人可以告诉我我想念的吗?还是我做错了什么?
该ChartAreas
系列仍然是空的(Count == 0
)。因此,您无法访问index处的项目0
。这导致你ArgumentOutOfRangeException
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句