我正在Silverlight中创建RadBarChart。
如果我对同一类中的Yvalue
和XCategory
值进行硬编码,则图表会显示正确的数据。
以下是我在Sample.cs类中使用Initializecomponent()
方法后调用的方法。
public void FillSampleChartData()
{
DataSeries dataSeries = new DataSeries();
dataSeries.Definition = new BarSeriesDefinition();
dataSeries.Add(new DataPoint() { YValue = 1127.13, XCategory = "Victor" });
dataSeries.Add(new DataPoint() { YValue = 1123.80, XCategory = "Kishore" });
dataSeries.Add(new DataPoint() { YValue = 9948.94, XCategory = "Vincent" });
RadChartSales.DefaultView.ChartArea.DataSeries.Add(dataSeries);
}
我怀疑是否从其他类调用相同的方法...条形图没有显示任何数据。让我知道为什么图表不显示数据。
//This is my original method
public void FillSampleChartData(IList collection)
{
int listcount = collection.Count;
int count = -1;
double[] myArray1 = new double[listcount];
string[] myArray2 = new string[listcount];
foreach (BizFramework.Web.Model.SalesBySalesPersonSummary_Result dtvws in collection)
{
count++;
myArray1[count] = Convert.ToDouble(dtvws.Amount);
myArray2[count] = dtvws.Salesperson;
}
DataSeries dataSeries = new DataSeries();
dataSeries.Definition = new BarSeriesDefinition();
if (myArray1.Count() > 0)
{
for (int i = 0; i < myArray1.Count(); i++)
{
dataSeries.Add(new DataPoint() { YValue = myArray1[i], XCategory = myArray2[i] });
}
RadChartSales.DefaultView.ChartArea.DataSeries.Add(dataSeries);
}
}