2

我正在silverlight 中创建RadBarChart。

如果我在同一个类中硬编码YvalueXCategory值,则图表显示正确的数据。

下面是我Initializecomponent()在 Sample.cs 类中的方法之后调用的方法。

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);
        }
    }
4

0 回答 0