Do you support dynamic series creation?

7 posts, 0 answers
  1. Mark
    Mark avatar
    17 posts
    Member since:
    Dec 2010

    Posted 22 Feb 2012 Link to this post

    Hello:
    I am considering using the ChartView control, and I have a requirement for dynamically generated series for a line chart.  I have a query that returns an varying number of accounts that I want to chart.  For example:

    account                amount
    ----------                -----------
    rent                     $1000
    auto                     $500
    office expenses    $400
    ...


    So, my question is: does ChartView component allow you to specify the "account" field so as to dynamically create a series for each unique value?

    Thanks,
    Mark
  2. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 27 Feb 2012 Link to this post

    Hello Mark,

    The current version of RadChartView does not provide built-in grouping support (that would result in dynamic number of generated series) but you can perform the grouping on your own with QueryableCollectionView (part of Telerik.Windows.Data.dll) and create the chart series dynamically based on the created groups like this:

    XAML
    <UserControl x:Class="SilverlightApplication15.MainPage"
        xmlns:local="clr-namespace:SilverlightApplication15"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
     
        <Grid>
     
            <telerik:RadCartesianChart x:Name="RadChart1" Palette="Metro">
     
                <telerik:RadCartesianChart.HorizontalAxis>
                    <telerik:DateTimeCategoricalAxis LabelFormat="yyyy/MM/dd" />
                </telerik:RadCartesianChart.HorizontalAxis>
                <telerik:RadCartesianChart.VerticalAxis>
                    <telerik:LinearAxis />
                </telerik:RadCartesianChart.VerticalAxis>
     
                <telerik:RadCartesianChart.Grid>
                    <telerik:CartesianChartGrid MajorLinesVisibility="Y" />
                </telerik:RadCartesianChart.Grid>
            </telerik:RadCartesianChart>
     
        </Grid>
    </UserControl>

    C#
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Windows.Controls;
    using Telerik.Windows.Controls.ChartView;
    using Telerik.Windows.Data;
     
    namespace SilverlightApplication15
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
     
                List<BusinessObject> data = new List<BusinessObject>();
                data.Add(new BusinessObject("Rent", 1000, DateTime.Today.AddDays(1)));
                data.Add(new BusinessObject("Auto", 5000, DateTime.Today.AddDays(1)));
                data.Add(new BusinessObject("Auto", 7000, DateTime.Today.AddDays(2)));
                data.Add(new BusinessObject("Auto", 900, DateTime.Today.AddDays(3)));
                data.Add(new BusinessObject("Auto", 900, DateTime.Today.AddDays(4)));
                data.Add(new BusinessObject("Office Expenses", 1000, DateTime.Today.AddDays(1)));
                data.Add(new BusinessObject("Office Expenses", 2000, DateTime.Today.AddDays(2)));
                data.Add(new BusinessObject("Office Expenses", 3000, DateTime.Today.AddDays(3)));
                data.Add(new BusinessObject("Office Expenses", 500, DateTime.Today.AddDays(4)));
                data.Add(new BusinessObject("Rent", 1000, DateTime.Today.AddDays(2)));
                data.Add(new BusinessObject("Rent", 2000, DateTime.Today.AddDays(3)));
                data.Add(new BusinessObject("Rent", 3000, DateTime.Today.AddDays(4)));
                data.Add(new BusinessObject("Rent", 1500, DateTime.Today.AddDays(5)));
                data.Add(new BusinessObject("Office Expenses", 1500, DateTime.Today.AddDays(5)));
                data.Add(new BusinessObject("Auto", 900, DateTime.Today.AddDays(5)));
     
                QueryableCollectionView qcv = new QueryableCollectionView(data);
                qcv.GroupDescriptors.Add(new GroupDescriptor() { Member = "Account" });
     
                foreach (var group in qcv.Groups)
                {
                    var lineSeries = new LineSeries();
                    lineSeries.ValueBinding = new PropertyNameDataPointBinding("Amount");
                    lineSeries.CategoryBinding = new PropertyNameDataPointBinding("Date");
                    lineSeries.ItemsSource = group as IEnumerable;
     
                    RadChart1.Series.Add(lineSeries);
                }
            }
        }
     
        public class BusinessObject
        {
            public BusinessObject(string account, double amount, DateTime date)
            {
                this.Account = account;
                this.Amount = amount;
                this.Date = date;
            }
     
            public string Account { get; set; }
            public double Amount { get; set; }
            public DateTime Date { get; set; }
        }
    }



    Kind regards,
    Giuseppe
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Barry
    Barry avatar
    2 posts
    Member since:
    Mar 2015

    Posted 06 Oct 2015 in reply to Giuseppe Link to this post

    How is this dynamic when you're adding every object explicitly.  How does telerik not have the most obvious functionality with their controls.  What are you guys doing?
  5. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 09 Oct 2015 Link to this post

    Hi Barry,

    I am afraid RadChartView still doesn't support grouping out of the box and we haven't include it in the planning for our next release. However, if you think this is a must-have feature you can submit a new feature request in our feedback portal. The more votes the item has the bigger priority will have its implementation.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Barry
    Barry avatar
    2 posts
    Member since:
    Mar 2015

    Posted 09 Oct 2015 Link to this post

    I got dynamic series to work with not too much extra effort. I also got those series lines in a spline series to either be drawn as a solid line or dashed line based on a simple flag in my object.  I will post the solution when I have some extra time.
  7. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 14 Oct 2015 Link to this post

    Hello Barry,

    I am glad to hear that you managed to implement the desired functionality. As for posting your solution, I believe that this will be quite helpful resource for our community.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. Yaroslav
    Yaroslav avatar
    123 posts
    Member since:
    Jan 2016

    Posted 26 Jul in reply to Martin Link to this post

    Hello, Barry. Please put here your resulting project with dynamically plotted chart. If this is possible of course.
Back to Top
DevCraft banner