Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Display all labels outside of pie chart with leading lines

Posted on 2014-03-04
6
Medium Priority
?
1,512 Views
Last Modified: 2014-03-17
I am generating a pie chart using vba from MSAccess.  With the best fit property setting, most of the labels are displayed outside of the pie chart.  However, we still have to manually drag out those labels that are short enough to fit within the pie slice.  

I would like to know how to iterate through each slice and determine which of the labels needs to be dragged away from the slice. Most importantly, I need to clearly display the leading lines connecting the labels to their respective slices.

Thanks.
0
Comment
Question by:yvroger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 1500 total points
ID: 39905797
Hi,

Instead of Best fit have tried Outside End

this code drag the labels by 2 points towards the outside so that you can see the lines

Sub macro()
ActiveChart.SeriesCollection(1).HasLeaderLines = True
ActiveChart.SeriesCollection(1).DataLabels.Position = xlLabelPositionOutsideEnd
Set chtArea = ActiveChart.ChartArea
MiddleOfAreaH = chtArea.Top + (chtArea.Height / 2)
MiddleOfAreaW = chtArea.Left + (chtArea.Width / 2)
For Each dtalbl In ActiveChart.SeriesCollection(1).DataLabels
If dtalbl.Top + (dtalbl.Height / 2) + chtArea.Top < MiddleOfAreaH Then
    dtalbl.Top = dtalbl.Top - 2
Else
    dtalbl.Top = dtalbl.Top + 2
End If

If dtalbl.Left + (dtalbl.Width / 2) + chtArea.Left < MiddleOfAreaW Then
    dtalbl.Left = dtalbl.Left - 2
Else
    dtalbl.Left = dtalbl.Left + 2
End If
Next
End Sub

Open in new window


Regards
0
 

Author Comment

by:yvroger
ID: 39908108
Rgonzo, your solution moved me in the right direction.  However, the height property in "dtalbl.Height" does not seem to work.  I get the error: "object doesn't support this property or method".

Please assist.  Thanks.
0
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 39908487
Hi,

Could you send a dummy example?

Regards
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:yvroger
ID: 39917928
Before I come up with a dummy example let me ask you a question.

Weren't trying to use chtarea.Height and chtarea.Width instead of dtalbl.Height and chtarea.Width respectively?

For example the expression "If dtalbl.Top + (dtalbl.Height / 2) + chtArea.Top < MiddleOfAreaH" should have been "If dtalbl.Top + (chtarea.Height / 2) + chtArea.Top < MiddleOfAreaH", correct?
0
 

Author Comment

by:yvroger
ID: 39918049
Is there a way to determine the angle of the data label from the chart axis?
0
 
LVL 53

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 1500 total points
ID: 39918067
Hi,

Chart area comprises the pie chart as well as the labels that's why you cannot have a precise angle for the labels. (Maybe you could but it would be really complicated)

I calculate the labels middle because if they a relatively large or high the direction to where I want to move them will be different

Regards
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question