Solved

Display all labels outside of pie chart with leading lines

Posted on 2014-03-04
6
1,471 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 52

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 52

Expert Comment

by:Rgonzo1971
ID: 39908487
Hi,

Could you send a dummy example?

Regards
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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 52

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

630 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