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

Different text for pie chart label and legend

8 Answers 544 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Federico
Top achievements
Rank 1
Federico asked on 15 Feb 2011, 12:09 PM
I would kindly need to know if it is possible to have a custom text for labels on a chart pie slice different from the one set for legend items. Pie chart is bound to an ObjectDataSource.

e.g. Chart label displays the numeric value of the item while legend holds a descriptive name for the item.

Thank you in advance !

Federico Blaseotto

8 Answers, 1 is accepted

Sort by
0
Accepted
Steve
Telerik team
answered on 16 Feb 2011, 08:52 AM
Hello Federico,

You can use the Series.Appearance.LegendDisplayMode property to specify what the legend would show.

Greetings,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Federico
Top achievements
Rank 1
answered on 16 Feb 2011, 11:27 AM
Thank You Steve.

But the solution doesn't work as expected.
I'll try to be a little clearer in describing this issue.

I've already used LegendDisplayMode as You suggest but the result is the one in attached fig1 (this is a bar chart but the problem is the same...).

You'll notice that Labels on the chart, the over-bar ones, are no more numbers (Y-value) but have the same value of the legend ones.

I've tried all combinations of Series.DataLabelColumn, DefaultLabel values but I can't succeed in having different values for X-axis labels, legend labels and in-chart label.

It seems like that they can't be bound to different objects or DataColumns and this could be a serious problem for me.

Thank You for the support !

Federico Blaseotto

0
Federico
Top achievements
Rank 1
answered on 16 Feb 2011, 11:34 AM
Sorry !
I've just found out that there's  a DataLabelsColumn in the PlotArea.X-Axis property and one with the same name in Series property.

Thank you for your support anyway !
0
Gil
Top achievements
Rank 1
answered on 27 Apr 2011, 07:00 AM
I'm still confused.  How do you use these properties to get numeric values (#Y or #%) for the chart item labels and strings for the Legend items?

I'm using a pie chart, if it matters.

Thanks for your help!
0
Steve
Telerik team
answered on 02 May 2011, 02:19 PM
Hello Gil,

You would have to create the chart series and items programmatically in the NeedDataSource event in order to be able to achieve your inquiry. A sample code that gets this done is available in the Data Binding Chart to a Generic List of Objects help article. Review it carefully and let us know how it goes.

Regards,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Gil
Top achievements
Rank 1
answered on 02 May 2011, 10:31 PM
Really?

I just want a different label in the chart and the legend.  I have to redefine the entire datasource to do that?  I want to keep the configurable datasource (with parameterized query) that I set up using the GUI, and all of the properties set there.
 
I'm ok with adding a little code, but I just want to set the chart item/legend labels; not everything!  Do you have an example of that?

Gil
0
Gil
Top achievements
Rank 1
answered on 12 May 2011, 06:44 PM
Just to follow up, Here's an example I got to work by combining a couple of other examples I found here:

private void MyChart_NeedDataSource(object sender, EventArgs e)
        {
            Telerik.Reporting.Processing.Chart procChart = (Telerik.Reporting.Processing.Chart)sender;
            string sql = @"SELECT [Market],[Signups] FROM ...";
            string connectionString = "Data Source=Servername;Initial Catalog=DBName;Integrated Security=True";
            SqlDataAdapter adapter = new SqlDataAdapter(sql, connectionString);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet);
            Telerik.Reporting.Chart defChart = (Telerik.Reporting.Chart)procChart.ItemDefinition;
            defChart.IntelligentLabelsEnabled = false;
            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 dataSet.Tables[0].Rows)
            {   
                ChartSeriesItem item = new ChartSeriesItem();
                item.YValue = Convert.ToDouble(dr["Signups"]);
                item.Name = (string)dr["Market"];
                item.Appearance.Exploded = true;
                item.Label.TextBlock.Text = dr["Signups"].ToString();
                serie.Items.Add(item);
            }
            defChart.Series.Add(serie); 
  
  
        }
0
Paul
Top achievements
Rank 1
answered on 11 Oct 2012, 05:50 AM
Hi Gil,

Can you show how does it look like now?

Thanks.
Tags
General Discussions
Asked by
Federico
Top achievements
Rank 1
Answers by
Steve
Telerik team
Federico
Top achievements
Rank 1
Gil
Top achievements
Rank 1
Paul
Top achievements
Rank 1
Share this question
or