Data not binding to RadBarChart in silverlight

5 posts, 0 answers
  1. kavitha
    kavitha avatar
    10 posts
    Member since:
    Jun 2011

    Posted 15 Nov 2012 Link to this post

    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);
            }
        }
  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 16 Nov 2012 Link to this post

    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.

  3. DevCraft banner
  4. kavitha
    kavitha avatar
    10 posts
    Member since:
    Jun 2011

    Posted 16 Nov 2012 Link to this post

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


  5. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 20 Nov 2012 Link to this post

    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.

  6. kavitha
    kavitha avatar
    10 posts
    Member since:
    Jun 2011

    Posted 20 Nov 2012 Link to this post

    Thanks for your help !
Back to Top
DevCraft banner