🔪
Cutting-Edge SwiftUI Apps
  • 📳Cutting-Edge SwiftUI Apps
  • TUTORIALS AND TIPS
    • 👋Introduction
  • ▶️Start with Charts
    • 👩‍💻Necessary Installations
    • Bar Mark
      • Chart Data driven
      • Xcode
    • Design as a time series
      • Bar graph
      • More data
      • Multi-series Line chart
  • ▶️New Window
    • 👩‍💻Necessary Installations
    • Single Unique Window
    • Menu bar
  • ▶️New Sharing
    • 👩‍💻Necessary Installations
    • ShareLink API
  • ▶️Start with Layout
    • Grid
  • WRAPPING IT UP
  • 🤸‍♀️Author
  • 📖References
Powered by GitBook
On this page
  1. Start with Charts

Bar Mark

Swift Charts calls visual elements "marks"

// We add a tabBar
// then we build a `BarMark` with 2 elements

import Charts
import SwiftUI

struct ContentView: View {
    @State private var selection = 2
    
    var body: some View {
        TabView(selection: $selection) {
            WinesTab()
                .tabItem {
                    Label("Wines", systemImage: "chart.bar.doc.horizontal")
                }
                .tag(1)
        }
    }
}

struct WinesTab: View {
    var body: some View {
        Chart {
            BarMark (
                x: .value("Name", "Margaux"),
                y: .value("Sales", 900)
            )
            BarMark(
                x: .value("Name", "Médoc"),
                y: .value("Sales", 460)
            )
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

PreviousNecessary InstallationsNextChart Data driven

Last updated 2 years ago

▶️