<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/visualising-data-with-a-hexagonal-heatmap-in-swift-charts-qmmjuenky" -->

---
title: Visualising data with a hexagonal heatmap in Swift Charts
description: A detailed walkthrough demonstrates how to build a hexagonal heatmap in Swift Charts using earthquake data from New Zealand's GeoNet catalogue. It covers...
canonical: https://daily.dev/posts/visualising-data-with-a-hexagonal-heatmap-in-swift-charts-qmmjuenky
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Visualising data with a hexagonal heatmap in Swift Charts | daily.dev
og:description: A detailed walkthrough demonstrates how to build a hexagonal heatmap in Swift Charts using earthquake data from New Zealand's GeoNet catalogue. It covers...
og:url: https://daily.dev/posts/visualising-data-with-a-hexagonal-heatmap-in-swift-charts-qmmjuenky
og:image: https://api.daily.dev/og/posts/QMMjUEnky.png
og:image:alt: Visualising data with a hexagonal heatmap in Swift Charts
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Visualising data with a hexagonal heatmap in Swift Charts

**[Nil Coalescing](https://daily.dev/sources/nilcoalescing)** · 11 min read · 0 upvotes · 0 comments

## Summary

A detailed walkthrough demonstrates how to build a hexagonal heatmap in Swift Charts using earthquake data from New Zealand's GeoNet catalogue. It covers arranging points in a hexagonal grid with axial coordinates, grouping observations into cells via cube-coordinate rounding, drawing a custom hexagon ChartSymbolShape, correcting proportions with perceptualUnitRect so hexagons tile correctly, and mapping earthquake frequency to color using a symmetric-log foreground style scale for better visual distinction of low-frequency cells.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://nilcoalescing.com/blog/VisualisingDataWithAHexagonalHeatmapInSwiftCharts>

## Questions this post answers

### How do I make hexagon symbols in Swift Charts tile together without gaps or overlap?

Define a custom perceptualUnitRect on the ChartSymbolShape to correct the hexagon's proportions, since the default drawing rectangle is a square while a regular hexagon in that orientation should have a width of about 0.866 times its height. Setting perceptualUnitRect to a CGRect with width 0.866 and horizontally centered offset lets Swift Charts size the symbol correctly so neighboring hexagons fit together with narrow gaps.

_daily.dev surfaces practical Swift Charts techniques like this for developers building custom chart symbols._

### How do you group geographic point data into a hexagonal grid using axial coordinates?

Convert longitude and latitude into fractional axial coordinates q and r using the inverse of the hex-to-pixel formula, then round them to the nearest integer cell. Independent rounding of q and r can misplace points near inclined edges, so a third coordinate s = -q - r is added to enforce a zero-sum cube-coordinate constraint, and the coordinate with the largest rounding error is adjusted to restore it.

_Developers implementing spatial binning can find this kind of grid-math walkthrough on daily.dev._

### Why does a linear color scale hide variation in low-value heatmap data, and what's an alternative?

A linear gradient maps most cells to the faint end of the scale when values are heavily skewed toward small numbers, making differences hard to see. Using a symmetricLog scale type (via chartForegroundStyleScale with type: .symmetricLog(slopeAtZero: 1)) compresses higher values and expands the visual range for lower ones while still supporting zero, revealing more variation at the cost of equal color intervals no longer meaning equal frequency differences.

_daily.dev helps developers compare scaling approaches like this when tuning data visualizations._

## Similar posts on daily.dev

- [Building an accessible calendar chart with Swift Charts](https://daily.dev/posts/building-an-accessible-calendar-chart-with-swift-charts-o2wzjpdld) · Nil Coalescing · 0 upvotes · 0 comments
- [Swift Charts Beyond the Basics: creating clear and beautiful data visualizations](https://daily.dev/posts/swift-charts-beyond-the-basics-creating-clear-and-beautiful-data-visualizations-mwhetv3bj) · Nil Coalescing · 0 upvotes · 0 comments
- [Visualizing Geo-Spatial Data in .NET MAUI with Interactive Charts and Maps](https://daily.dev/posts/visualizing-geo-spatial-data-in-net-maui-with-interactive-charts-and-maps-nc63xwlgq) · Syncfusion · 0 upvotes · 0 comments
- [Building a sunburst diagram in Swift Charts](https://daily.dev/posts/building-a-sunburst-diagram-in-swift-charts-pa8wdkc6c) · Nil Coalescing · 0 upvotes · 0 comments
- [New York City Hexmaps](https://daily.dev/posts/new-york-city-hexmaps-foysajhwi) · R-bloggers · 0 upvotes · 0 comments

---

Tags: [#ios](https://daily.dev/tags/ios), [#swift](https://daily.dev/tags/swift), [#data-visualization](https://daily.dev/tags/data-visualization)

[View this post on daily.dev](https://daily.dev/posts/visualising-data-with-a-hexagonal-heatmap-in-swift-charts-qmmjuenky)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Visualising data with a hexagonal heatmap in Swift Charts","url":"https://daily.dev/posts/visualising-data-with-a-hexagonal-heatmap-in-swift-charts-qmmjuenky","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/visualising-data-with-a-hexagonal-heatmap-in-swift-charts-qmmjuenky"},"datePublished":"2026-09-27T03:45:18.367Z","dateModified":"2026-09-27T03:45:41.888Z","description":"A detailed walkthrough demonstrates how to build a hexagonal heatmap in Swift Charts using earthquake data from New Zealand's GeoNet catalogue. It covers...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/21ec501a3b5c85e402505d4688ea1b9e?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/21ec501a3b5c85e402505d4688ea1b9e?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Nil Coalescing","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Nil Coalescing","logo":"https://media.daily.dev/image/upload/s--rcEu6sag--/f_auto,q_auto/v1785654899/logos/nilcoalescing?_a=BAMAMicg0","url":"https://daily.dev/sources/nilcoalescing"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/visualising-data-with-a-hexagonal-heatmap-in-swift-charts-qmmjuenky","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ios,swift,data-visualization","timeRequired":"PT11M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Nil Coalescing","item":"https://daily.dev/sources/nilcoalescing"},{"@type":"ListItem","position":3,"name":"Visualising data with a hexagonal heatmap in Swift Charts"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/visualising-data-with-a-hexagonal-heatmap-in-swift-charts-qmmjuenky#faq","mainEntity":[{"@type":"Question","name":"How do I make hexagon symbols in Swift Charts tile together without gaps or overlap?","acceptedAnswer":{"@type":"Answer","text":"Define a custom perceptualUnitRect on the ChartSymbolShape to correct the hexagon's proportions, since the default drawing rectangle is a square while a regular hexagon in that orientation should have a width of about 0.866 times its height. Setting perceptualUnitRect to a CGRect with width 0.866 and horizontally centered offset lets Swift Charts size the symbol correctly so neighboring hexagons fit together with narrow gaps. daily.dev surfaces practical Swift Charts techniques like this for developers building custom chart symbols."}},{"@type":"Question","name":"How do you group geographic point data into a hexagonal grid using axial coordinates?","acceptedAnswer":{"@type":"Answer","text":"Convert longitude and latitude into fractional axial coordinates q and r using the inverse of the hex-to-pixel formula, then round them to the nearest integer cell. Independent rounding of q and r can misplace points near inclined edges, so a third coordinate s = -q - r is added to enforce a zero-sum cube-coordinate constraint, and the coordinate with the largest rounding error is adjusted to restore it. Developers implementing spatial binning can find this kind of grid-math walkthrough on daily.dev."}},{"@type":"Question","name":"Why does a linear color scale hide variation in low-value heatmap data, and what's an alternative?","acceptedAnswer":{"@type":"Answer","text":"A linear gradient maps most cells to the faint end of the scale when values are heavily skewed toward small numbers, making differences hard to see. Using a symmetricLog scale type (via chartForegroundStyleScale with type: .symmetricLog(slopeAtZero: 1)) compresses higher values and expands the visual range for lower ones while still supporting zero, revealing more variation at the cost of equal color intervals no longer meaning equal frequency differences. daily.dev helps developers compare scaling approaches like this when tuning data visualizations."}}]}
```

