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

Binding to generic list of objects

1 Answer 44 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 02 Oct 2012, 07:13 AM
Hi I have a generic list of objects that I would like to bind to a bar graph that have the following properties:

public decimal TotalValue
{
    get
    {
        return _totalValue;
    }
    set
    {
        _totalValue = value;
    }
}
 
public decimal TotalHours
{
    get
    {
        return _totalHours;
    }
    set
    {
        _totalHours = value;
    }
}
 
public string FieldActivityNameWUnit
{
    get
    {
        return _fieldActivityNameWUnit;
    }
    set
    {
        _fieldActivityNameWUnit = value;
    }
}
 
public int ActivityMonth
{
    get
    {
        return _activityMonth;
    }
    set
    {
        _activityMonth = value;
    }
}
 
public string ActivityMonthName
{
    get
    {
        return _activityMonthName;
    }
    set
    {
        _activityMonthName = value;
    }
}
 
public string FieldActivity
{
    get
    {
        return _fieldActivity;
    }
    set
    {
        _fieldActivity = value;
    }
}

If you look at the attached graphic, really all I want is the totalvalue displayed.not the month number or the totalhours.  how do I get rid of these other two series?  here is my code so far:
    protected void CreateYearChart()
    {
 
        RadChartProjectActivityYearly.Legend.Clear();
        RadChartProjectActivityYearly.Series.Clear();
 
        FieldActivity _activity = FieldActivityService.GetByID(Int32.Parse(ddlFieldActivity.SelectedValue.ToString()));
        RadChartProjectActivityYearly.ChartTitle.TextBlock.Text = _activity.Unit + " in " + ddlDetailYear.SelectedItem.Text;
 
        List<FactProjectActivityTotalsByMonth> _factsBar1 = FactProjectActivityTotalsByMonthService.GetForYear(Int32.Parse(ddlDetailYear.SelectedItem.Text), Int32.Parse(ddlFieldActivity.SelectedValue.ToString()));
 
        RadChartProjectActivityYearly.DataSource = _factsBar1;
 
        RadChartProjectActivityYearly.Legend.Visible = true;
 
//        RadChartProjectActivityYearly.Series[0].DataYColumn = "TotalValue";
        RadChartProjectActivityYearly.PlotArea.XAxis.DataLabelsColumn = "ActivityMonthName";
         
        RadChartProjectActivityYearly.DataBind();
        RadChartProjectActivityYearly.AutoLayout = true;
 
        foreach (Telerik.Charting.ChartSeries series in RadChartProjectActivityYearly.Series)
        {
            Debug.WriteLine(series.Name);
            //if (series.Name != "TotalValue")
            //{
            //    RadChartProjectActivityYearly.Series.Remove(series);
            //}
        }
 
        //RadChartProjectActivityYearly.RemoveSeriesAt(2);
        //RadChartProjectActivityYearly.RemoveSeriesAt(0);

I thought about creating the series manually but then I lose the X-axis labels so ideally I'd like to be able to databind to only one property of the object in the underlying list.  Her is the declaration:
<telerik:RadChart ID="RadChartProjectActivityYearly" runat="server" skin="Forest" Width="1000px" >
<Legend>
 <Appearance Position-AlignedPosition="TopRight"></Appearance>
 </Legend>
    <PlotArea>
        <XAxis AutoScale="False" DataLabelsColumn="ActivityMonthName" ></XAxis>
    </PlotArea>
</telerik:RadChart>
thanks for the help

1 Answer, 1 is accepted

Sort by
0
Petar Kirov
Telerik team
answered on 04 Oct 2012, 04:03 PM
Hello Jonathan,

I believe your problem is that you have commented out this line:
RadChartProjectActivityYearly.Series[0].DataYColumn = "TotalValue";
Without it the chart can not know which property to treat as YValue.

You can check this example of data binding to generic list of objects for reference.

Let us know how it works for you.

Regards,
Petar Kirov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Chart (Obsolete)
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Share this question
or