如何使用 List<string> 设置 radChart 值的 Y 轴标签 [英] How to set the Y-Axis Label of radChart values using List<string>
问题描述
如何使用 radChart 设置 X 轴标签,因为我收到 IndexOutOfRange 异常我不知道这背后的原因是什么.
How can I set the X-Axis labels using radChart as I am getting the IndexOutOfRange Exception I do not what is the reason behaind this.
public void setchart()
{
radChart.Clear();
radChart.BringToFront();
radChart.ChartTitle.TextBlock.Text = "Total Number Of Units Per Rack";
this.Controls.Add(radChart);
radChart.Dock =DockStyle.Fill;
radChart.PlotArea.Appearance.Dimensions.Height = 500;
radChart.PlotArea.XAxis.AxisLabel.Visible = true;
radChart.PlotArea.XAxis.AxisLabel.TextBlock.Text = "UnitProcessDetailType";
radChart.PlotArea.XAxis.AxisLabel.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.Red;
radChart.PlotArea.XAxis.Appearance.Width = 1;
radChart.PlotArea.XAxis.Appearance.Color = System.Drawing.Color.Red;
radChart.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = 45;
radChart.PlotArea.YAxis.AxisLabel.Visible = true;
radChart.PlotArea.YAxis.AxisLabel.TextBlock.Text = "Number Of Units";
radChart.PlotArea.YAxis.AxisLabel.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.Red;
radChart.PlotArea.YAxis.Appearance.Width = 1;
radChart.PlotArea.YAxis.Appearance.Color = System.Drawing.Color.Red;
radChart.Chart.Skin = "Sunset";
Telerik.Charting.ChartSeries chartSeries = new Telerik.Charting.ChartSeries();
chartSeries.Name = "Number Of Units Per Type";
chartSeries.Type = Telerik.Charting.ChartSeriesType.Bar;
chartSeries.Appearance.BarWidthPercent = 70;
radChart.PlotArea.XAxis.AutoScale = false;
ReportGrid.Controls.Add(radChart);
List<string> xaxisLabel = new List<string>();
List<string> yaxislabel = new List<string>();
if (masterTab1.HeaderGrid.CurrentRow.Cells[0].Value.ToString() == "Sales Quotes by Quote Status")
{
DataTable table = new DataTable();
table = Adapter.SalesQuotesbyQuoteStatus(GroupList.SelectedText.ToString(), TimePeriodList.SelectedText.ToString());
int number = table.Rows.Count;
int column = table.Columns.Count;
radChart.PlotArea.XAxis.AddRange(1, number, 1);
radChart.PlotArea.YAxis.AddRange(1 , 1 , 1);
foreach (DataRow dr in table.Rows)
{
xaxisLabel.Add(dr["X_Axis"].ToString());
yaxislabel.Add(dr["Y_Axis"].ToString());
}
for (int i = 0; i < table.Rows.Count; i++)
{
chartSeries.AddItem(Convert.ToDouble(yaxislabel[i]), xaxisLabel[i]);
}
for (int xaxis = 0; xaxis < xaxisLabel.Count; xaxis++)
{
radChart.PlotArea.XAxis[xaxis].TextBlock.Text = xaxisLabel[xaxis];
}
for (int yaxis = 0; yaxis < yaxislabel.Count; yaxis++)
{
radChart.PlotArea.YAxis[yaxis].TextBlock.Text = yaxislabel[yaxis];
}
radChart.Series.Add(chartSeries);
}
}
List 也包含值,因为我已经一遍又一遍地检查它,现在我不知道实际问题是什么?
The List also contain values as I have checked it again and again , now I do not know what is the actual problem?
推荐答案
我不知道确切的问题,但错误背后的原因 IndexOutOfRangeException 可能如下所示,
I dont know the exact problem but the reason behind the error IndexOutOfRangeException may be like this as follows,
例如:在 Main 中,我们使用了一个长度为 100 的新数组.这意味着该数组是对大小为 100 个整数的对象数据的引用.可以通过数组下标访问数组元素,如数组[0]、数组[1]、数组[99].
For Example: In Main, we use a new array of length 100. This means that the array is a reference to object data of size 100 integers. You can access the array elements through array subscripts, as with array[0], array[1], through array[99].
提示:您可以访问的最高索引等于总长度减一.如果访问超过 99 的索引,则会收到 IndexOutOfRangeException.
Tip:The top index you can access equals the total length minus one. If you access an index past 99, you get an IndexOutOfRangeException.
这篇关于如何使用 List<string> 设置 radChart 值的 Y 轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!