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

Pie Chart with Business Object datasource

2 Answers 212 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rodion
Top achievements
Rank 1
Rodion asked on 10 Dec 2008, 01:17 PM
Hi,

I have a simple business object:

class Obj
{
    public string Label {get; set; }
    public int Data {get; set; }
}

Now I need to display a collection of such objects in a pie chart so when I handle my NeedDataSource event of that chart I have the following:

Telerik.Reporting.Processing.Chart chart = sender as Telerik.Reporting.Processing.Chart;
chart.DataSource = this.dataSource;


where this.dataSource is a List<Obj>, everything works perfectly with the exception that the labels of the slices keep showing the Obj.Data value, instead I want it to show Obj.Label value, what do I need to do?

I hope this is a trivial question, but I can't seem to get it. I tried setting PlotArea.XAxis.DataLabelsColumn and Series.DataXColumn but nothing seems to work...

Thank you
Rodion

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Chavdar
Telerik team
answered on 12 Dec 2008, 03:08 PM
Hello Rodion,

You have to set the DataLabelsColumn property of the chart series to the name of the corresponding property from the business object. Consider the following code snippet:

void chart1_NeedDataSource(object sender, System.EventArgs e)
{
            Telerik.Reporting.Processing.Chart chart =
                (Telerik.Reporting.Processing.Chart) sender;

            Telerik.Reporting.Chart chartDef =
                (Telerik.Reporting.Chart) chart.ItemDefinition;

            chartDef.Series.Clear();
            ChartSeries s = new ChartSeries();
            s.Type = ChartSeriesType.Pie;
            chartDef.Series.Add(s);
            s.DataYColumn       = "Value";
            s.DataLabelsColumn  = "Label";

            List<ChartData> list = new List<ChartData>();
            list.Add(new ChartData(1, "CCC"));
            list.Add(new ChartData(2, "BBB"));
            list.Add(new ChartData(3, "AAA"));

            chart.DataSource = list;
}


class ChartData
        {
            double value;
            string label;
            string label2;

            public ChartData(double value, string label)
            {
                this.value = value;
                this.label = label;
                this.label2 = label2;
            }

            public double Value
            {
                get { return this.value; }
                set { this.value = value; }
            }

            public string Label
            {
                get { return this.label; }
                set { this.label = value; }
            }           
        }


Hope this helps.

Best wishes,
Chavdar
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rodion
Top achievements
Rank 1
answered on 12 Dec 2008, 05:53 PM
Thank you
Tags
General Discussions
Asked by
Rodion
Top achievements
Rank 1
Answers by
Chavdar
Telerik team
Rodion
Top achievements
Rank 1
Share this question
or