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

Do you support dynamic series creation?

6 Answers 189 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 23 Feb 2012, 01:32 AM
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

6 Answers, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 27 Feb 2012, 04:08 PM
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 >>
0
Barry
Top achievements
Rank 1
answered on 07 Oct 2015, 04:22 AM
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?
0
Martin Ivanov
Telerik team
answered on 09 Oct 2015, 04:28 PM
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
0
Barry
Top achievements
Rank 1
answered on 09 Oct 2015, 04:39 PM
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.
0
Martin Ivanov
Telerik team
answered on 14 Oct 2015, 10:54 AM
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
0
Dmitry
Top achievements
Rank 1
answered on 26 Jul 2016, 01:44 PM
Hello, Barry. Please put here your resulting project with dynamically plotted chart. If this is possible of course.
Tags
ChartView
Asked by
Mark
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Barry
Top achievements
Rank 1
Martin Ivanov
Telerik team
Dmitry
Top achievements
Rank 1
Share this question
or