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

Can't set X Axis custom values

1 Answer 87 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Antonio Simoes
Top achievements
Rank 1
Antonio Simoes asked on 26 May 2010, 10:27 AM
Hello,

I have tried every single example found to set my XAxis values but none of them seems to work for me.
I'm populating a Line chart manually with a List of objects and it works just fine. I am also setting the XAxis ValueFormat to ShortDate and whatever I do, this includes clearing the collection of ChartAxisItems and adding with my own, I only get dates in the range of 1899/01/01...1900/01/01 etc etc even when I'm explicitly adding items with dates like "2010-01-01...2010-06-01" in OADate format.
I tried to set the Min and Max values of my XAxis to 01/01/2010 to 01/07/2010 but it doesn't produce any effect.


Here's some code because I know you'll ask:

NeedDataSource Event:
 chart1.PlotArea.XAxis.Appearance.ValueFormat = Telerik.Reporting.Charting.Styles.ChartValueFormat.ShortDate;  
              
            List<Issue> issues = new List<Issue>();  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-01-2010")});  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-01-2010") });  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-01-2010") });  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-02-2010") });  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-02-2010") });  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-03-2010") });  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-04-2010") });  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-04-2010") });  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-04-2010") });  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-04-2010") });  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-04-2010") });  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-05-2010") });  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-05-2010") });  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-05-2010") });  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-06-2010") });  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-06-2010") });  
            issues.Add(new Issue() { CategoryName = "Teste1"DueDate = DateTime.Parse("01-06-2010") });  
 
 
            var cats = issues.GroupBy(x => x.CategoryName);  
 
            List<string> Categorias = new List<string>();  
            chart1.Series.Clear();  
 
            chart1.PlotArea.XAxis.MinValue = DateTime.Parse("01-01-2010").ToOADate();  
            chart1.PlotArea.XAxis.MaxValue = DateTime.Parse("01-07-2010").ToOADate();  
            foreach (var cat in cats)  
            {  
                Categorias.Add(cat.Key);  
            }  
 
 
            foreach (string categoria in Categorias)  
            {  
                var issuesissuesPerCat = issues.Where(x => x.CategoryName == categoria);  
                var groupedIssues = issuesPerCat.GroupBy(x => x.DueDate.ToString("dd/MM/yyyy"));  
 
                ChartSeries series = new ChartSeries();  
                series.Type = ChartSeriesType.Line;  
 
 
                foreach (var issue in groupedIssues)  
                {  
                    ChartSeriesItem csitem = new ChartSeriesItem();  
                    csitem.YValue = issue.Count();  
                    series.Items.Add(csitem);  
                    chart1.PlotArea.XAxis.AddItem(issue.Key);  
                     
                }  
 
 
                chart1.Series.Add(series);  
            } 

and in the attached file is the result of this code...

P.S.: For the record, I'm using the latest version of Q1 2010 (Version=4.0.10.423)

 

1 Answer, 1 is accepted

Sort by
0
Antonio Simoes
Top achievements
Rank 1
answered on 26 May 2010, 11:40 AM
Ok I solved the problem...but I had to set at design time a dummy series (wich I'm clearing at runtime) and had to set the ValueFormat to shortdate at design time aswell...At runtime I am setting these attributes in the needdatasource event, do I have to set them somewhere else in order to work?
Tags
General Discussions
Asked by
Antonio Simoes
Top achievements
Rank 1
Answers by
Antonio Simoes
Top achievements
Rank 1
Share this question
or