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

Using Line Chart in reports

2 Answers 136 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
HelpdeskLisboa
Top achievements
Rank 1
HelpdeskLisboa asked on 24 May 2010, 02:49 PM
Hello,

I'm trying to produce a Line chart that will show me the evolution of the amount of issues for each category over time.
I'm not being able to acomplish it.

I'm looping through a List of categories and for each category I'm creating a ChartSeries where I'm adding ChartSeriesItems containing as YValue their count.

As a side note, for each category I'm fetching its associated Issues and then I'm groupping them by the month and year part of its creation date.

The final output is exactly what I need but...When I run the chart, the dates are showing up on the Y axis (hey what?!!) although I'm explicitly assigning the count of Issues to the YValue of each ChartSeriesItem!

Here's my code (the important part of it) :

I have an IEnumerable that creates my ChartSeries (each category will be a serie):

        private IEnumerable<ChartSeries> CategoryEvolutionSeries(Telerik.Reporting.Chart chart)  
        {  
 
             
            var cats = issues.GroupBy(x => x.CategoryName);  
            List<string> Categorias = new List<string>();  
 
            foreach (var cat in cats)  
            {  
                Categorias.Add(cat.Key);  
            }  
 
 
            foreach (string cat in Categorias)  
            {  
                var IssuesPerCat = issues.Where(x => x.CategoryName == cat);  
                var group = IssuesPerCat.GroupBy(x => x.DateCreated.ToString("yyyy/MM"));  
 
                ChartSeries series = new ChartSeries();  
                series.Appearance.PointMark.Dimensions.Width = 5;  
                series.Appearance.PointMark.Dimensions.Height = 5;  
                series.Appearance.PointMark.FillStyle.MainColor = Color.Black;  
                series.Appearance.PointMark.Visible = true;  
 
                group = group.OrderBy(x => x.Key);  
 
                series.Appearance.LabelAppearance.Visible = false;  
                series.Appearance.ShowLabels = true;  
                series.Name = cat;  
                series.Type = ChartSeriesType.Line;  
 
                foreach (var issue in group)  
                {  
                    ChartSeriesItem item = new ChartSeriesItem();  
                    item.YValue = issue.Count();  
                    series.Items.Add(item);  
                }  
 
                yield return series;  
 
 
            }  
 
        } 

Then, I assign the series to my chart on the NeedDataSource Event:

                defChart.Series.Clear();  
 
                foreach (ChartSeries item in evolseries)  
                {  
                    defChart.Series.Add(item);  
                } 

Since I can't send you the project files (they're part of a big big solution with lots of dependencies) I'm attaching a screenshot of the resulting Chart.

Please help, what am I doing wrong here??

2 Answers, 1 is accepted

Sort by
0
HelpdeskLisboa
Top achievements
Rank 1
answered on 24 May 2010, 05:18 PM
Hello again,

I found out why it wasn't working. I forgot I had set the Series Orientation to Horizontal on the chart designer.
Setting it back to Vertical obviously solved the problem...

However, I'm having an aditional problem. My X Axis is showing 1,2,3,4,5,6...etc. I changed the ValueFormat to shortdate and the CustomFormat to "YYYY/MM" but instead of showing the actual values (e.g.: 2010/01...2010/12... <- this values im setting on the ChartSeriesItem Label Textblock) it shows 1899/12...1900/01...1900/02...

Im populating my series by hand, meaning I'm not assigning a datasource to my chart...so I guess DataLabelColumn property is not an option for me.

I also tried setting the X Axis items manually on the Chart...but without success :|

Any hints?
0
Ves
Telerik team
answered on 26 May 2010, 01:58 PM
Hello,

Straight to your second question -- the chart supports the OLE Automation equivalent of DateTime. You can use the DateTime.ToOADate method to retrieve it -- it is actually a double value. You have already found that you need to set ValueFormat and CustomFormat. Now, all you need to do is set the XValue property of each ChartSeriesItem with the value, which corresponds to that date, it would be something like that:

item.XValue = issue.DateCreated.ToOADate();

within the loop, which creates the ChartSeriesItems.

One last note -- you may want to set XAxis.IsZeroBased to false in this case, as OA dates for 2010 are greater than 40000, so having all the dates from 1899 till now would not make the chart look very good. With this property, the chart will calculate the X axis range automatically, so that only a period with actual values is shown.

Best regards,
Ves
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
Tags
General Discussions
Asked by
HelpdeskLisboa
Top achievements
Rank 1
Answers by
HelpdeskLisboa
Top achievements
Rank 1
Ves
Telerik team
Share this question
or