.NET Framework Bookmark and Share   
 index > Chart Controls for .NET Framework > Display percentage and value in data labels?
 

Display percentage and value in data labels?

I'm trying to create the following pie chart:


I am able to create a pie chart that has the values (511, 112, and 187) as the data labels and the correct text in the legend. I'm using DataBindXY to do this and then creating a legend. As you can see in the chart above, though, I need to have the value AND percentage displayed in the data label.

How can this be accomplished?
im1dermike

Set the series label:

	series.Label = "#VALY #PERCENT"

Or, set the label for each datapoint in the series

	For i As Integer = 0 To series.Points.Count - 1
		series.Points(i).Label = "#VALY #PERCENT"
		'If you need the text in the legend to be something specific
		series.Points(i).LegendText = "point specific text " & i
	Next

For more keywords: http://msdn.microsoft.com/en-us/library/dd456687(VS.100).aspx

Ofcourse, in the for-loop, you could set the label to anything you want without using keywords.

sipla

Set the series label:

	series.Label = "#VALY #PERCENT"

Or, set the label for each datapoint in the series

	For i As Integer = 0 To series.Points.Count - 1
		series.Points(i).Label = "#VALY #PERCENT"
		'If you need the text in the legend to be something specific
		series.Points(i).LegendText = "point specific text " & i
	Next

For more keywords: http://msdn.microsoft.com/en-us/library/dd456687(VS.100).aspx

Ofcourse, in the for-loop, you could set the label to anything you want without using keywords.

sipla
Perfect sipla. I further formatted the percentage like this:
chart.Series["Series1"].Points[i].Label = "#VALY\n(#PERCENT{0%})"
im1dermike

You can use google to search for other answers

Custom Search

More Threads

• Reducing space between column categories
• getting 'error creating control' in VS2008 for chart controls in page
• Build Bar Chart Dynamically
• stacked Bar setting xvalue
• Custom Axis Labels
• HOW TO ADD THE RADOR CHART AND HOW TO ENTER THE DATA IN THE RADOR CHART
• Multiple cursors
• Connecting lines for supplemental pie chart?
• Reading Y values at cursor position
• Pie Chart