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

Display Data Item on Pie Chart Legend

10 Answers 321 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 20 Aug 2012, 04:27 AM
Hi, I am new to the Telerik Reporting. I am trying to display the data item on the legend but could not do so. I need some help. I have attached a screen shot on what I want to do. Appreciate some help.

10 Answers, 1 is accepted

Sort by
0
Hadib Ahmabi
Top achievements
Rank 1
answered on 20 Aug 2012, 11:18 AM
From the properties of the concrete series set: 
LegendDisplayMode = ItemLabels
0
Andy
Top achievements
Rank 1
answered on 20 Aug 2012, 01:10 PM
Hi, thanks for your reply. I have checked the Designer.cs - InitializationComponent section, there is a statement:
chartSeries1.Appearance.LegendDisplayMode = Telerik.Reporting.Charting.ChartSeriesLegendDisplayMode.ItemLabels;

If I do any modification, I will get an error. Please advice if there are any other place that I need to look.

Regards
Andy Tan


0
Steve
Telerik team
answered on 20 Aug 2012, 04:47 PM
Hello Andy,

Our ProductLineSales demo report contains a pie chart with LegendDisplayMode set to ItemLabels that works as expected. Those demos are installed along with the product so you can open the report locally and review it. One thing that could intervene with any settings of the chart (not only styles) is the Skin property which can override such settings. So if you're using a Skin, it is a good idea to set the customizations of the chart in the report constructor after InitializeComponent or style the whole chart manually (i.e. without setting a Skin).

All the best,
Steve
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

0
Andy
Top achievements
Rank 1
answered on 21 Aug 2012, 05:43 AM
Hi, I followed your advice by removing the skin and in deed it is able to display the Legend but as item 1,2,3.... If configure the datalabelcolumn setting, the legend is correct but the pie chart data lable cannot show actual value.
 
Attached is the screen shot that explain the problem.

Following is the listing of the designer.cs:

private

 

 

void InitializeComponent()

{

Telerik.Reporting.Charting.

 

ChartAxisItem chartAxisItem1 = new Telerik.Reporting.Charting.ChartAxisItem();

Telerik.Reporting.Charting.

 

ChartAxisItem chartAxisItem2 = new Telerik.Reporting.Charting.ChartAxisItem();

Telerik.Reporting.Charting.

 

ChartAxisItem chartAxisItem3 = new Telerik.Reporting.Charting.ChartAxisItem();

Telerik.Reporting.Charting.

 

ChartAxisItem chartAxisItem4 = new Telerik.Reporting.Charting.ChartAxisItem();

Telerik.Reporting.Charting.

 

ChartAxisItem chartAxisItem5 = new Telerik.Reporting.Charting.ChartAxisItem();

Telerik.Reporting.Charting.

 

ChartSeries chartSeries1 = new Telerik.Reporting.Charting.ChartSeries();

 

this.pageHeaderSection1 = new Telerik.Reporting.PageHeaderSection();

 

this.detail = new Telerik.Reporting.DetailSection();

 

this.chart1 = new Telerik.Reporting.Chart();

 

this.sqlDataSource1 = new Telerik.Reporting.SqlDataSource();

 

this.pageFooterSection1 = new Telerik.Reporting.PageFooterSection();

((System.ComponentModel.

 

ISupportInitialize)(this)).BeginInit();

 

//

 

// pageHeaderSection1

 

//

 

this.pageHeaderSection1.Height = Telerik.Reporting.Drawing.Unit.Inch(2D);

 

this.pageHeaderSection1.Name = "pageHeaderSection1";

 

//

 

// detail

 

//

 

this.detail.Height = Telerik.Reporting.Drawing.Unit.Inch(2.8000001907348633D);

 

this.detail.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {

 

this.chart1});

 

this.detail.Name = "detail";

 

//

 

// chart1

 

//

 

this.chart1.BitmapResolution = 96F;

 

this.chart1.DataSource = this.sqlDataSource1;

 

this.chart1.DefaultType = Telerik.Reporting.Charting.ChartSeriesType.Pie;

 

this.chart1.ImageFormat = System.Drawing.Imaging.ImageFormat.Emf;

 

this.chart1.Legend.TextBlock.Visible = true;

 

this.chart1.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Inch(0.19999997317790985D), Telerik.Reporting.Drawing.Unit.Inch(0.20000012218952179D));

 

this.chart1.Name = "chart1";

 

this.chart1.PlotArea.XAxis.AxisLabel.Appearance.Visible = true;

 

this.chart1.PlotArea.XAxis.AxisLabel.Visible = true;

 

this.chart1.PlotArea.XAxis.IsZeroBased = false;

chartAxisItem1.TextBlock.Text =

 

"F Disagreed";

chartAxisItem1.Value =

 

new decimal(new int[] {

1,

0,

0,

0});

chartAxisItem2.TextBlock.Text =

 

"Disagreed";

chartAxisItem2.Value =

 

new decimal(new int[] {

2,

0,

0,

0});

chartAxisItem3.TextBlock.Text =

 

"Neutral";

chartAxisItem3.Value =

 

new decimal(new int[] {

3,

0,

0,

0});

chartAxisItem4.TextBlock.Text =

 

"Agreed";

chartAxisItem4.Value =

 

new decimal(new int[] {

4,

0,

0,

0});

chartAxisItem5.TextBlock.Text =

 

"F Agreed";

chartAxisItem5.Value =

 

new decimal(new int[] {

5,

0,

0,

0});

 

this.chart1.PlotArea.XAxis.Items.AddRange(new Telerik.Reporting.Charting.ChartAxisItem[] {

chartAxisItem1,

chartAxisItem2,

chartAxisItem3,

chartAxisItem4,

chartAxisItem5});

 

this.chart1.PlotArea.XAxis.MaxItemsCount = 5;

 

this.chart1.PlotArea.XAxis.MaxValue = 5D;

 

this.chart1.PlotArea.XAxis.MinValue = 1D;

chartSeries1.Appearance.FillStyle.MainColor = System.Drawing.

 

Color.Aqua;

chartSeries1.Appearance.LegendDisplayMode = Telerik.Reporting.Charting.

 

ChartSeriesLegendDisplayMode.ItemLabels;

chartSeries1.DataYColumn =

 

"Value";

chartSeries1.DefaultLabelValue =

 

"#%";

chartSeries1.Name =

 

"Series 1";

chartSeries1.Type = Telerik.Reporting.Charting.

 

ChartSeriesType.Pie;

 

this.chart1.Series.AddRange(new Telerik.Reporting.Charting.ChartSeries[] {

chartSeries1});

 

this.chart1.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(4.8000001907348633D), Telerik.Reporting.Drawing.Unit.Inch(2.6000001430511475D));

 

this.chart1.Style.BackgroundColor = System.Drawing.Color.White;

 

//

 

// sqlDataSource1

 

//

 

this.sqlDataSource1.ConnectionString = "Survey";

 

this.sqlDataSource1.Name = "sqlDataSource1";

 

this.sqlDataSource1.SelectCommand = "SELECT Grade, Value\r\nFROM Result1";

 

//

 

// pageFooterSection1

 

//

 

this.pageFooterSection1.Height = Telerik.Reporting.Drawing.Unit.Inch(2D);

 

this.pageFooterSection1.Name = "pageFooterSection1";

 

//

 

// Report1

 

//

 

this.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {

 

this.pageHeaderSection1,

 

this.detail,

 

this.pageFooterSection1});

 

this.Name = "Report1";

 

this.PageSettings.Margins.Bottom = Telerik.Reporting.Drawing.Unit.Inch(1D);

 

this.PageSettings.Margins.Left = Telerik.Reporting.Drawing.Unit.Inch(1D);

 

this.PageSettings.Margins.Right = Telerik.Reporting.Drawing.Unit.Inch(1D);

 

this.PageSettings.Margins.Top = Telerik.Reporting.Drawing.Unit.Inch(1D);

 

this.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.Letter;

 

this.Style.BackgroundColor = System.Drawing.Color.White;

 

this.Width = Telerik.Reporting.Drawing.Unit.Inch(6D);

((System.ComponentModel.

 

ISupportInitialize)(this)).EndInit();



Please help.

Regards
Andy tan

0
Steve
Telerik team
answered on 21 Aug 2012, 08:51 AM
Hello Andy,

Please check the related help article that will help you provide different names for the chart item labels and the values on the plot area - How-To: Programmatically Data Binding Chart to a Generic List of Objects. The general idea is that you programmatically add the chart series item, which gives you more granular control on how to display item labels and plot values. Otherwise you will have to show either equal labels or just the item labels/ plot values. This is a limitation specific to pie chart type.

I hope that helps.

Greetings,
Steve
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

0
Andy
Top achievements
Rank 1
answered on 22 Aug 2012, 02:55 PM
Hi,

I used the sample code provide in your link to try out but get this error message on this instruction:

Telerik.Reporting.Processing.Chart procChart = (Telerik.Reporting.Processing.Chart)sender;

The error message is:

An error has occurred while processing Report 'productreport': Unable to cast object of type 'Telerik.Reporting.Processing.Report' to type 'Telerik.Reporting.Processing.Chart'.

I am not sure where I am missing out.

Regards
Andy Tan

0
Accepted
Steve
Telerik team
answered on 23 Aug 2012, 08:27 AM
Hello Andy,

Judging by the error, you must have wired the Report NeedDataSource instead of the chart NeedDataSource. Please wire the appropriate event handler.

Regards,
Steve
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

0
Saman
Top achievements
Rank 1
answered on 27 Jun 2013, 08:08 PM
hello, i used the sample code but i get this error:

An error has occurred while processing Report 'chart2': Unable to cast object of type 'Telerik.Reporting.Processing.Report' to type 'Telerik.Reporting.Processing.Chart'.

what is wrong?

my code:

 private void chart2_NeedDataSource(object sender, EventArgs e)
        {
            Telerik.Reporting.Processing.Chart procChart = (Telerik.Reporting.Processing.Chart)sender;
            Telerik.Reporting.Chart defChart = (Telerik.Reporting.Chart)procChart.ItemDefinition;
            defChart.Series[0].DefaultLabelValue = string.Empty;
            defChart.IntelligentLabelsEnabled = false;
            Class1 obj_class = new Class1();
            DataTable source = new DataTable();
            source = obj_class.retrvTBL("select SUM(OS.oscount)as sumcount,OS.os from OS group by os");
            ChartSeries serie = new ChartSeries();
            serie.Type = ChartSeriesType.Pie;
            serie.Clear();
            serie.Appearance.LegendDisplayMode = Telerik.Reporting.Charting.ChartSeriesLegendDisplayMode.ItemLabels;
            serie.Appearance.ShowLabelConnectors = true;

            foreach (DataRow dr in source.Rows)
            {
                ChartSeriesItem item = new ChartSeriesItem();
                item.YValue = Convert.ToDouble(dr["sumcount"]);
                item.Name = (string)dr["sumcount"] + " - #%";
                item.Appearance.Exploded = true;
                item.Label.TextBlock.Text = dr["os"].ToString();
                serie.Items.Add(item);
            }

            defChart.Series.Add(serie);
            
        }

Regards
saman
0
Saman
Top achievements
Rank 1
answered on 28 Jun 2013, 09:03 AM
Please anybody can help meeee?
0
Unknown
Top achievements
Rank 1
answered on 02 Jul 2013, 04:25 PM
You are handling the NeedDataSource of the report itself, therefore the sender is of type Report. You will have to create the same event handler, but for the chart itself.
Tags
General Discussions
Asked by
Andy
Top achievements
Rank 1
Answers by
Hadib Ahmabi
Top achievements
Rank 1
Andy
Top achievements
Rank 1
Steve
Telerik team
Saman
Top achievements
Rank 1
Unknown
Top achievements
Rank 1
Share this question
or