Sunday 29 May 2011

Creating Pie-Chart From Telerik RadChart In Wpf



Drag and Drop A radChart Control in your Xaml file
 <telerik:RadChart Name="radChartDemo" Width="400" Height="400" HorizontalAlignment="Left" VerticalAlignment="Top" />

In Xamal.cs Create User defined method LoadChart() like this-

        private void loadChart()
        {
            DataTable tbl = new DataTable();
            DataColumn col = new DataColumn("Value");
            col.DataType = typeof(int);
            tbl.Columns.Add(col);
            col = new DataColumn("ExcerciseType");
            col.DataType = typeof(string);
            tbl.Columns.Add(col);

            tbl.Rows.Add(new object[] { 30, "ExerciseA" });
            tbl.Rows.Add(new object[] { 60, "ExerciseB" });
            tbl.Rows.Add(new object[] { 10, "ExerciseC" });


            SeriesMapping seriesMapping = new SeriesMapping();
            seriesMapping.SeriesDefinition = new PieSeriesDefinition();

            ItemMapping itemMapping = new ItemMapping();
            itemMapping.DataPointMember = DataPointMember.YValue;
            itemMapping.FieldName = "Value";
            seriesMapping.ItemMappings.Add(itemMapping);

            itemMapping = new ItemMapping();
            itemMapping.DataPointMember = DataPointMember.LegendLabel;
            itemMapping.FieldName = "ExcerciseType";
            seriesMapping.ItemMappings.Add(itemMapping);

            radChartDemo.SeriesMappings.Add(seriesMapping);

            //RadChart1.DefaultSeriesDefinition = new PieSeriesDefinition();
            radChartDemo.ItemsSource = tbl;

        }
call LoadChart() method in Class constructor and you will see a pie chart at runtime.



1 comment:

  1. Hi I come across your article via google search.
    Can you please provide the solution.

    I want the labels on pie slices like JAVA : 10 and
    WCF : 20 .this is the format I need .I know how to do this through tooltip.

    please help me.

    ReplyDelete