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

Hide Label Based on Value

5 Answers 107 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 2
Ron asked on 01 Mar 2010, 03:33 PM
Hello,

I have a pie chart where sometimes several values it contains are so small will cause the labels to overlap.  I have tried using the IntelligentLabels, but this does not work out very well in most instances.  What I would like to do is hide the labels of those items that are below a certain percentage.  I am having problems trying to figure out how I would go about that.  Does anyone have an samples of how I can hide the label of an item when it is below 2%.  I assume this is the the ItemDataBound event of the chart, but some of the sample I have tried have not really worked yet.

Thanks,
Ron

5 Answers, 1 is accepted

Sort by
0
Ron
Top achievements
Rank 2
answered on 02 Mar 2010, 01:09 PM
I was able to do this based on the value of the data versus the percentage as so:

If e.dataitem("Number of Devices") < 5 Then e.SeriesItem.Label.Visible = False

However, doing this by number is not optimal as this is always changing and I would still need to do it by percentage.  As of right now the only thing I can think of is doing an additional query for each item that databinds to calculate the sum of the original query then compare the value that is databinding at the moment and if below a certain percentage of that sum to hide the label.  Seems like there should be a better way than this though.
0
Ron
Top achievements
Rank 2
answered on 02 Mar 2010, 01:22 PM
Well after a little playing around I answered my own question, the final code in the ItemDataBound event is:

Dim percent as String = e.SeriesItem.Label.TextBlock.Text.Trim("%")
If Convert.ToInt32(percent) < 1 Then e.SeriesItem.Label.Visible = False

Hope this helps anyone else that may have had this question.

Thanks,
Ron
0
Ron
Top achievements
Rank 2
answered on 02 Mar 2010, 05:11 PM
Sigh... unfortunately this was not the solution.  So I am still stuck with the problem of overlapping labels and the intelligentlabels not working as needed in most situations.  So I still need to be able to hide the labels based on the percentage.
0
Ves
Telerik team
answered on 03 Mar 2010, 07:58 AM
Hi Ron Montecalvo,

Here's a suggestion. You can sum the YValues in ItemDataBound event handler. Then, in DataBound event handler calculate the threshold (ex. sum = 47, 2% threshold would be 0.94), then loop on all the items, compare the YValue to the threshold and hide the label.

And alternative approach would be to set the Name property of the ChartSeriesItem in ItemDataBound. The value set to this property will appear in the legend. This way you can hide all the labels and have all the values displayed in the legend.

Best regards,
Ves
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
Ron
Top achievements
Rank 2
answered on 03 Mar 2010, 11:22 PM
Thanks for the information, I will have to give that method a try.  In the meantime I did solve it by doing a query in the beginning and storing the value so that I could calculate the amount at each dataitembound event to the total to get it's percentage and hide based if it was too low.

Thanks,
Ron
Tags
Chart (Obsolete)
Asked by
Ron
Top achievements
Rank 2
Answers by
Ron
Top achievements
Rank 2
Ves
Telerik team
Share this question
or