Hide Label Based on Value

Thread is closed for posting
6 posts, 0 answers
  1. Ron
    Ron avatar
    86 posts
    Member since:
    Sep 2009

    Posted 01 Mar 2010 Link to this post

    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
  2. Ron
    Ron avatar
    86 posts
    Member since:
    Sep 2009

    Posted 02 Mar 2010 Link to this post

    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.
  3. Ron
    Ron avatar
    86 posts
    Member since:
    Sep 2009

    Posted 02 Mar 2010 Link to this post

    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
  4. Ron
    Ron avatar
    86 posts
    Member since:
    Sep 2009

    Posted 02 Mar 2010 Link to this post

    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.
  5. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 03 Mar 2010 Link to this post

    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.
  6. Ron
    Ron avatar
    86 posts
    Member since:
    Sep 2009

    Posted 03 Mar 2010 Link to this post

    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
Back to Top