アラートダイアログ上にWkWebViewを作成し、その上でAMChartsによる円グラフを表示するAppleScriptです。
ダイアログでテーマ選択したのちに、グラフ表示を行います。
—> Download ampiechartSample(AppleScript bundle with Script Library and HTMLs)
AppleScript名:AMChartsで円グラフをダイアログ上に表示 v3.scptd |
— – Created by: Takaaki Naganoya – Created on: 2020/06/25 — – Copyright © 2020 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions use webD : script "webDialogLib" set themeList to {"dark", "dataviz", "material", "kelly", "frozen", "moonrisekingdom", "spiritedaway"} set aSel to (choose from list themeList with prompt "Select Theme") if aSel = false then set aTheme to false set aHTML to "index_notheme.html" else set aTheme to contents of first item of aSel if aTheme = "dark" then set aTheme to false set aHTML to "index_dark.html" else set aHTML to "index.html" end if end if set aList to {{label:"ひよこ王国", value:403}, {label:"ぴよぴよ連邦", value:301}, {label:"ぴよランド", value:101}, {label:"ぴよー", value:65}} set bList to sortRecListByLabel(aList, {"value"}, {false}) of me –降順ソート –https://www.amcharts.com/demos/pie-chart/ set mePath to path to me set resPath to (mePath as string) & "Contents:Resources:" & aHTML set myStr to (read (resPath as alias) as «class utf8») as string set jsonStr to array2DToJSONArray(bList) of me as string if aTheme = false then set aString to current application’s NSString’s stringWithFormat_(myStr, jsonStr) as string else set aString to current application’s NSString’s stringWithFormat_(myStr, aTheme, aTheme, jsonStr) as string end if set paramObj to {myMessage:"Simple Pie Chart", mySubMessage:"This is a AMCharts test", htmlStr:aString, jsDelimiters:{"<script>", "</script>"}, viewSize:{1000, 550}} webD’s displayWebDialog(paramObj) on array2DToJSONArray(aList) set anArray to current application’s NSMutableArray’s arrayWithArray:aList set jsonData to current application’s NSJSONSerialization’s dataWithJSONObject:anArray options:(0 as integer) |error|:(missing value) set resString to current application’s NSString’s alloc()’s initWithData:jsonData encoding:(current application’s NSUTF8StringEncoding) return resString end array2DToJSONArray –リストに入れたレコードを、指定の属性ラベルの値でソート on sortRecListByLabel(aRecList as list, aLabelStr as list, ascendF as list) set aArray to current application’s NSArray’s arrayWithArray:aRecList set aCount to length of aLabelStr set sortDescArray to current application’s NSMutableArray’s new() repeat with i from 1 to aCount set aLabel to (item i of aLabelStr) set aKey to (item i of ascendF) set sortDesc to (current application’s NSSortDescriptor’s alloc()’s initWithKey:aLabel ascending:aKey) (sortDescArray’s addObject:sortDesc) end repeat return (aArray’s sortedArrayUsingDescriptors:sortDescArray) as list end sortRecListByLabel |
More from my site
(Visited 193 times, 2 visits today)