Solved

Display all labels outside of pie chart with leading lines

Posted on 2014-03-04
6
1,347 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
  • 3
  • 3
6 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 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 48

Expert Comment

by:Rgonzo1971
ID: 39908487
Hi,

Could you send a dummy example?

Regards
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 48

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 500 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now