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

[Solved] Using Class Model for Dynamic Chart Series Provider as Source?

1 Answer 135 Views
Chart for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Lance
Top achievements
Rank 1
Lance asked on 21 Dec 2012, 07:17 AM
Hello,

I've recently stumbled upon a problem which is, I'm trying to use my own Custom Class in binding to use as the source for my Dynamic Chart's Series Provider. Problem is that it does not work and shows, "No Data found" displayed. When I try to convert the data instead and use a List<List<object>>, the data is displayed properly..

But due to various reasons, one of which is using a class parameter to specify the kind of SeriesDescriptor to use using a SeriesDescriptorSelector, I need to use my custom Class.

Here is my code below of my Classes:

public class ChartData
    {
        public string ID { get; set; }
        public string TileID { get; set; }
        public string Title { get; set; }
        public string XAxisLabel { get; set; }
        public string YAxisLabel { get; set; }
 
        public List<ChartGroup> Groups = new List<ChartGroup>();
        public List<string> GroupIDList = new List<string>();
 
        public ChartData(string parID, string parTileID, string parTitle, string parXLabel, string parYLabel)
        {
            ID = parID;
            TileID = parTileID;
            Title = parTitle;
            XAxisLabel = parXLabel;
            YAxisLabel = parYLabel;
 
            Groups = new List<ChartGroup>();
            GroupIDList = new List<string>();
        }
    }
 
    public class ChartGroup
    {
        public List<ChartRow> Rows {get;set;}
 
        public ChartGroup()
        {
            Rows = new List<ChartRow>();
        }
 
    }
 
    public class ChartRow
    {
        public double Value { get; set; }
        public string Name { get; set; }
 
        public ChartRow( string parName, double parCount)
        {
            Value = parCount;
            Name = parName;
        }
    }

And here is my code-behind (see formatted block for my conversion into List<List<object>>):

Style seriesstyle = new Style(typeof(BarSeries));
            seriesstyle.Setters.Add(new Setter(BarSeries.CombineModeProperty, Telerik.Charting.ChartSeriesCombineMode.Stack));
 
            CategoricalSeriesDescriptor seriesdescriptor = new CategoricalSeriesDescriptor();
            seriesdescriptor.ValuePath = "Value";
            seriesdescriptor.CategoryPath = "Name";
            seriesdescriptor.Style = seriesstyle;
 
            sourceChart.SeriesProvider.SeriesDescriptors.Add(seriesdescriptor);
 
            //HERE IS CODE BEHIND FOR CONVERSION INTO LIST<LIST<OBJECT>>
            //List<List<ChartRow>> groups = new List<List<ChartRow>>();
 
            //for (int i = 0; i < ((ChartData)source.Data).Groups.Count; i++)
            //{
               // groups.Add(new List<ChartRow>());
                //for (int j = 0; j < ((ChartData)source.Data).Groups[i].Rows.Count; j++)
               // {
                    //groups[i].Add(((ChartData)source.Data).Groups[i].Rows[j]);
                //}
           // }
 
            //sourceChart.SeriesProvider.Source = groups;
            sourceChart.SeriesProvider.Source = ((ChartData)source.Data).Groups;    // <-- using this does not work

Hope you can help me! Thank you!

1 Answer, 1 is accepted

Sort by
0
Accepted
Ivaylo Gergov
Telerik team
answered on 25 Dec 2012, 02:54 PM
Hello Lance,

Thank you for your interest.

The ChartSeriesProvider.Source property expects to receive collections of objects which it knows how to operate with. In the current scenario this should be collections of ChartRow objects. I suggest you to make the ChartData.Group property of List<List<ChartRow>> type. When you fill this collection you can pass it directly ChartGroup.Rows instead of ChartGroup objects.

However I will proceed this question to the development team and if there is an additional information which can be useful to you I will contact you shortly.

I hope this helps. If you have any other questions do not hesitate to contact us again.


 

All the best,
Ivaylo Gergov
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
Chart for XAML
Asked by
Lance
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Share this question
or