The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle General (http://forums.omnigroup.com/forumdisplay.php?f=10)
-   -   Using Adjustable Wedge to create a pie chart in AppleScript (http://forums.omnigroup.com/showthread.php?t=29725)

realbrick 2013-05-23 09:58 AM

Using Adjustable Wedge to create a pie chart in AppleScript
 
I've seen other AppleScript for creating pie charts in OmniGraffle that involved using trigonometry. The Adjustable Wedge object (in the Common stencil under shapes) lets you do it much more simply.

The code is below. I put a post describing it here:
[url]http://omnigraffletips.blogspot.com/2013/05/drawing-pie-chart-with-applescript.html[/url]

Cheers,

- Joseph

tell application "OmniGraffle Professional 5"
set pieLoc to {50, 50}
set pieDiameter to 400
set wedgeValues to {24, 55, 77, 130, 37}
set wedgeColors to {{1, 0, 0}, {0, 1, 1}, {1, 0, 1}, {0, 0, 1}, {0, 1, 0}}
set wedgeStartAngle to 0

set wedges to {}

set sumOfWedgeValues to 0
repeat with wedgeValue in wedgeValues
set sumOfWedgeValues to sumOfWedgeValues + wedgeValue
end repeat

repeat with i from 1 to count of wedgeValues
set wedgeDegrees to ((item i of wedgeValues) / sumOfWedgeValues) * 360
set wedgeEndAngle to wedgeStartAngle + wedgeDegrees
tell canvas of front window
set wedge to make new shape at end of graphics with properties {name:"AdjustableWedge", size:{pieDiameter, pieDiameter}, origin:pieLoc, startAngle:wedgeStartAngle, endAngle:wedgeEndAngle, draws shadow:false, draws stroke:false, fill color:item i of wedgeColors}
end tell

set end of wedges to wedge

set wedgeStartAngle to wedgeEndAngle
end repeat

assemble wedges
end tell


All times are GMT -8. The time now is 07:34 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.