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

Databinding Unique Values on x-axis

1 Answer 95 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 2
Michael asked on 09 Jan 2009, 05:39 PM
Hi,

I am databinding multiple series to my chart.  Each series is money spent per month per person.

So, say I have three people a, b, and c.  I am trying to plot their spending over aperiod of 6 months (all the same months Jan 2008 through June 2008).

My data is coming back via an ObjectDataSource with these fields:

Person | Amount | Month

The key portion of my code looks like this:
       
        //add a series for each person 
        for (int i = 0; i <= (selectedPersons.Count - 1); i++) 
        { 
            ChartSeries chartSeries = new ChartSeries(); 
            chartSeries.Name = selectedPersonNames[i].ToString(); 
            chartSeries.Type = ChartSeriesType.Line; 
            chartSeries.DataYColumn = "$"
            usageChart.Series.Add(chartSeries); 
        } 
         
 
        //set the x axis labels, adjust any appearance, and bind the data 
        usageChart.DataSource = personExpenses
        usageChart.PlotArea.XAxis.DataLabelsColumn = "Month"
        usageChart.DataBind(); 


The problem I am running into is that the x-axis is adding a total of 18 months (6 for each of the three people).  The x-axis looks like this:

Jan Feb Mar Apr May Jun Jul Jan Feb Mar Apr May Jun Jul Jan Feb Mar Apr May Jun Jul

I want 6 months and three series -- How can I get the x-axis to display only unique values?

Thanks,

Mike

1 Answer, 1 is accepted

Sort by
0
Accepted
Ves
Telerik team
answered on 12 Jan 2009, 09:43 AM
Hi Michael,

You can take advantage of the DataGroupColumn property of RadChart. You can find more details here.

Here is a simple example of databinding RadChart in this manner:

protected void Page_Load(object sender, EventArgs e) 
    { 
 
        List<MyObject> myList = new List<MyObject>(); 
 
        myList.Add(new MyObject { Amount = 3, Person = "Person1", Month = "Jan" }); 
        myList.Add(new MyObject { Amount = 6, Person = "Person2", Month = "Jan" }); 
        myList.Add(new MyObject { Amount = 7, Person = "Person3", Month = "Jan" }); 
        myList.Add(new MyObject { Amount = 4, Person = "Person1", Month = "Feb" }); 
        myList.Add(new MyObject { Amount = 5, Person = "Person2", Month = "Feb" }); 
        myList.Add(new MyObject { Amount = 9, Person = "Person3", Month = "Feb" }); 
 
        RadChart1.DataSource = myList; 
        RadChart1.DataGroupColumn = "Person"
        RadChart1.PlotArea.XAxis.DataLabelsColumn = "Month"
        RadChart1.DataBind(); 
    } 
 
    public class MyObject  
    { 
        public double Amount { getset; } 
        public string Person { getset; } 
        public string Month { getset; } 
    } 

The chart configuration would remain the same when used with ObjectDatasource. Hope this helps.

All the best,
Ves
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Chart (Obsolete)
Asked by
Michael
Top achievements
Rank 2
Answers by
Ves
Telerik team
Share this question
or