This is a migrated thread and some comments may be shown as answers.

Data not binding to RadBarChart in silverlight

4 Answers 112 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
kavitha
Top achievements
Rank 1
kavitha asked on 15 Nov 2012, 07:58 AM

I am creating RadBarChart in silverlight.

If I hardcode the Yvalue and XCategory values in the same class then the chart shows correct data.

Below is the method I am calling after Initializecomponent() method in Sample.cs class.

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

I have doubt if I call same method from other class...barchart not showing any data. Let me know why chart is not displaying data.

//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 Answers, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 16 Nov 2012, 07:53 AM
Hello Kavi,

There should be no difference between the two - if you call the FillSampleChartData from the class itself or from another class. I have prepared a simple project to demonstrate this works correctly. The chart is originally empty. When I click the button, the chart gets properly populated. I have also attached a snapshot of the output it produces before and after the button click.

Kind regards,
Petar Marchev
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
kavitha
Top achievements
Rank 1
answered on 16 Nov 2012, 11:39 AM
Thanks for your reply Petar Marchev,

I am using mvvm model. 
1. In view i have chart 
2. In view model i have logic.

In my code i am creating object for my chart class in view model. i hope for this only data is not binding to chart. 

Can you please create object for sample class and call the FillSampleChartData() method.( I know here no need to create object)
But i am curious how it will work with new object .

using your code :
// In  MainPage.xmal.cs  can you create object for sample class, 

 sl_Chart_630076.Sample s= new Sample();
                s.FillSampleChartData();


0
Petar Marchev
Telerik team
answered on 20 Nov 2012, 08:07 AM
Hello Kavi,

I see no point into doing this test. If I create a new instance of Sample - it is not visualized anywhere on the screen, so it wouldn't matter if I call the method or not. If you have a specific question about our controls let us know how we can help.

Kind regards,
Petar Marchev
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
kavitha
Top achievements
Rank 1
answered on 20 Nov 2012, 08:14 AM
Thanks for your help !
Tags
Chart
Asked by
kavitha
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
kavitha
Top achievements
Rank 1
Share this question
or