Hi
I was trying to generate the Pie chart. Everything was fine except the Legend. It is giving me - Item1, Item2 Item3 etc instead of actual item values...
Have look at the code,
Dim chaSer As New ChartSeries
radChart.AddChartSeries(chaSer)
radChart.ChartTitle.TextBlock.Text = "Polling Result"
radChart.Skin = "WebBlue"
radChart.Attributes.Add("Palette", "Colorful")
getRespDt()
chaSer.Type = ChartSeriesType.Pie
chaSer.DefaultLabelValue = "#%"
chaSer.Appearance.ShowLabels = True
chaSer.DataYColumn = "Count"
chaSer.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels
radChart.DataSource = dtPoll
radChart.DataBind()
Response.ContentType = "image/png"
radChart.Save(Response.OutputStream, ImageFormat.Jpeg)
Thanks,
Pradip
I was trying to generate the Pie chart. Everything was fine except the Legend. It is giving me - Item1, Item2 Item3 etc instead of actual item values...
Have look at the code,
Dim chaSer As New ChartSeries
radChart.AddChartSeries(chaSer)
radChart.ChartTitle.TextBlock.Text = "Polling Result"
radChart.Skin = "WebBlue"
radChart.Attributes.Add("Palette", "Colorful")
getRespDt()
chaSer.Type = ChartSeriesType.Pie
chaSer.DefaultLabelValue = "#%"
chaSer.Appearance.ShowLabels = True
chaSer.DataYColumn = "Count"
chaSer.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels
radChart.DataSource = dtPoll
radChart.DataBind()
Response.ContentType = "image/png"
radChart.Save(Response.OutputStream, ImageFormat.Jpeg)
Thanks,
Pradip
8 Answers, 1 is accepted
0
Hello pradip,
There are a couple of steps you need to do:
Where the "LegendNameColumn" string should be replaced with the name of the column from your data source that holds the legend labels.
Best wishes,
Velin
the Telerik team
There are a couple of steps you need to do:
- Register for the ItemDataBound event and set value to the Name property of each item. This value will be displayed in the legend. Here is the sample code:
Copy Code<telerik:RadChart ID="RadChart1" runat="server" OnItemDataBound="ItemDataBound"> public void ItemDataBound(object sender, ChartItemDataBoundEventArgs e) { e.SeriesItem.Name = dataSource.Rows[e.SeriesItem.Index]["LegendName column"].ToString(); } - Set the series Appearance.LegendDisplayMode to ItemLabels. This instructs the legend to show labels for each item in the series.
Copy Code
<Series> <telerik:ChartSeries Appearance-LegendDisplayMode="ItemLabels" Type="Pie" DataYColumn="CurrentDrainPercentage" /> </Series>
Where the "LegendNameColumn" string should be replaced with the name of the column from your data source that holds the legend labels.
Best wishes,
Velin
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
Celeste
Top achievements
Rank 1
answered on 11 Nov 2010, 07:14 PM
I am experiencing the same issue. The chart is using a SqlDataSource but the
SqlDataSource object has no .Rows property. Please identify the object type of your dataSource object or assist. Thank you.
SqlDataSource object has no .Rows property. Please identify the object type of your dataSource object or assist. Thank you.
0
Hi Celeste,
You can find the respective row from the data source using code like this:
Where "Name" is actually column name used for legend labels.
Kind regards,
Ryan
the Telerik team
You can find the respective row from the data source using code like this:
public void ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
{
e.SeriesItem.Name = (e.DataItem as DataRowView).Row["Name"].ToString();
}
Where "Name" is actually column name used for legend labels.
Kind regards,
Ryan
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Celeste
Top achievements
Rank 1
answered on 17 Nov 2010, 07:06 PM
Thank you, that helped!
0
kamal
Top achievements
Rank 1
answered on 24 May 2011, 07:54 AM
i have a problem with pie chart legends
this is the code i have implemented :
PieSeriesDefinition lineDefinition = new PieSeriesDefinition();
lineDefinition.SeriesName = strElementName;
lineDefinition.LegendDisplayMode = LegendDisplayMode.SeriesLabel;
i have data for 2 elements, chart shows data for 2 elements but the color of both the elements is same, also it shows only one legend, it should have shown 2 legends.
i am using auto generated legends.
if i generate legends, how to color those legends to get the default colors as i am not changing the default colors of the chart area.
this is the code i have implemented :
PieSeriesDefinition lineDefinition = new PieSeriesDefinition();
lineDefinition.SeriesName = strElementName;
lineDefinition.LegendDisplayMode = LegendDisplayMode.SeriesLabel;
i have data for 2 elements, chart shows data for 2 elements but the color of both the elements is same, also it shows only one legend, it should have shown 2 legends.
i am using auto generated legends.
if i generate legends, how to color those legends to get the default colors as i am not changing the default colors of the chart area.
0
Marbry
Top achievements
Rank 1
answered on 31 Aug 2011, 07:49 PM
The last example given retrieves the correct data, but it's not being displayed in the legend.
The example you gave doesn't seem to be right, why would you populate the name, then set the display mode to label?
Shouldn't there be a ChartSeriesLegendDisplayMode.ItemNames ?
The example you gave doesn't seem to be right, why would you populate the name, then set the display mode to label?
Shouldn't there be a ChartSeriesLegendDisplayMode.ItemNames ?
0
Hello Marbry,
I agree, this is a bit misleading. The Name provides the value to display in the legend, while the Label provides the string for the label. In case you need them equal, you can populate them with the same values.
Kind regards,
Ves
the Telerik team
I agree, this is a bit misleading. The Name provides the value to display in the legend, while the Label provides the string for the label. In case you need them equal, you can populate them with the same values.
Kind regards,
Ves
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
0
marinus bosman
Top achievements
Rank 1
answered on 06 Oct 2011, 08:07 AM
[Deleted: Posted in Wriong Thread]