{"id":3277,"date":"2023-06-10T11:33:31","date_gmt":"2023-06-10T15:33:31","guid":{"rendered":"https:\/\/michaelrowe01.com\/?p=3277"},"modified":"2023-06-10T11:33:32","modified_gmt":"2023-06-10T15:33:32","slug":"explore-pie-charts-and-interactivity-in-swift-charts","status":"publish","type":"post","link":"https:\/\/michaelrowe01.com\/index.php\/blog\/explore-pie-charts-and-interactivity-in-swift-charts\/","title":{"rendered":"Explore pie charts and interactivity in Swift Charts"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"660\" height=\"371\" data-attachment-id=\"3278\" data-permalink=\"https:\/\/michaelrowe01.com\/index.php\/blog\/explore-pie-charts-and-interactivity-in-swift-charts\/attachment\/%ef%a3%bfwwdc23-35\/\" data-orig-file=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-35.png?fit=1920%2C1080&amp;ssl=1\" data-orig-size=\"1920,1080\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"\uf8ffWWDC23-35\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-35.png?fit=660%2C371&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-35.png?resize=660%2C371&#038;ssl=1\" alt=\"\" class=\"wp-image-3278\" srcset=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-35.png?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-35.png?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-35.png?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-35.png?resize=1536%2C864&amp;ssl=1 1536w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-35.png?w=1920&amp;ssl=1 1920w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-35.png?w=1320&amp;ssl=1 1320w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/figure>\n\n\n\n<p>Pie charts<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Pie charts are new to Swift Charts<\/li>\n\n\n\n<li>They don\u2019t have axises and don\u2019t really show precision &#8211; so great for casual, intuitive analysis.<\/li>\n\n\n\n<li>You can dd a sector mark &#8211; you can customize the look- increasing the radius &#8211; you get a donut charts<\/li>\n\n\n\n<li>The code for a pie chart is pretty easy &#8211;<\/li>\n<\/ul>\n\n\n\n<p>Chart(data, id: \\.name) { element in<\/p>\n\n\n\n<p>SectorMark (<\/p>\n\n\n\n<p>angle: .value(\u201cSales), element.sales)<\/p>\n\n\n\n<p>)<\/p>\n\n\n\n<p>.foregroundStyle(by: .value(\u201cName\u201d, element.name))<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>That\u2019s it.&nbsp; By using Sector mark, you end up with the PieChart, you can add other properties and modifiers, via .innerRadius, .angularInset, and .cornerRadius<\/li>\n<\/ul>\n\n\n\n<p>Selection<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This is interactivity for your chart.&nbsp; Check out heart rate chart by apple.<\/li>\n\n\n\n<li>Using valueSelection chartXSelection(value: $selector) modeifier allows you to capture the selection information and then provide additional information like a popover or annotation, you can use DragGestures to do a selection range<\/li>\n<\/ul>\n\n\n\n<p>Scrolling<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Navigating the data, just add .chartScrollableAxes a set a domain of .chartXVisibleDomain, and you provide a .chartScrollPosition as a binding, to say what part of the data to show in the scroll section.&nbsp; Adding .chartScrollTargetBehavior allows you to snap to boundaries when things scroll out of the view.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Pie charts Chart(data, id: \\.name) { element in SectorMark ( angle: .value(\u201cSales), element.sales) ) .foregroundStyle(by: .value(\u201cName\u201d, element.name)) } Selection Scrolling<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"hide_page_title":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[2,3],"tags":[739,740,680],"class_list":["post-3277","post","type-post","status-publish","format-standard","hentry","category-blog","category-personal-softwareandit","tag-day-6","tag-swift-charts","tag-wwdc23"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2aMa8-QR","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/3277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/comments?post=3277"}],"version-history":[{"count":1,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/3277\/revisions"}],"predecessor-version":[{"id":3279,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/3277\/revisions\/3279"}],"wp:attachment":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/media?parent=3277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/categories?post=3277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/tags?post=3277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}