見出し画像

【じっくりSw1ftUI62】実践編32〜第44章 SwiftUI Chartsを使ったプレゼンテーションデータ

さてと、前回

で、

プログレスバーの基本

はやったので〜〜〜今回は、

Charts

をやってく🕺いよいよ、

で触れていたところに入ってく〜〜〜

今回は、特にWEBに公開されていない箇所みたいなんだけど、

実は、毎回、プロットに従ってるだけで、

一切、本そのままのコードでは書いていない

ので、

今回もオイラの学びでオイラ自身のコードで書いてく🕺

んだば早速


じっくり第44章を読んでく👓

ここでポイント①:SwiftUIのChartsフレームワークを使って、

  • AreaMark

  • BarMark

  • LineMark

  • PointMark

  • RectangleMark

  • RuleMark

みたいなものをビューに組み込むって書いてんね👀💦
で、そいつらが何って話なんだけど、要は

グラフ

ってだけの話。ま、

BIツールのアプリ化

みたいなことをしたい人もいるだろうから、

SwiftUIでもちゃんとグラフ機能は用意してんぜ

って感じかな藁😝
(※日本の市販本だとこの機能を書いたのをオイラは見たことがない藁😝)

てな感じで、今回も

早速動かす

今回も

import SwiftUI

struct Essentials44ContentsView: View {
    var body: some View {
        Text("Hello,E44")
    }
}

#Preview {
    Essentials44ContentsView()
}

てな感じで、

まっさらな新規ファイルを用意〜〜〜

チャート図を使うには、

import Charts

をインポートしてあげて〜〜〜

import SwiftUI
import Charts

struct Essentials44ContentsView: View {
    var body: some View {
        ScrollView{
         E44ChartStandardView()
        }
        .safeAreaPadding()
    }
}

struct E44ChartStandardView: View {
    var body: some View {
        Text("Hello")
    }
}
#Preview {
    Essentials44ContentsView()
}

てな感じにして組み込んでく

struct E44ChartStandardView: View {
    var body: some View {
        Chart{
            AreaMark(
                x:PlottableValue.value("品目","🍎"),
                y:PlottableValue.value("個数",500)
            )
            AreaMark(
                x:PlottableValue.value("品目","🍊"),
                y:PlottableValue.value("個数",400)
            )
            AreaMark(
                x:PlottableValue.value("品目","🍌"),
                y:PlottableValue.value("個数",600)
            )
        }
    }
}

てな感じにしてあげると、、、

てな感じ

これをデータと連携させることまで念頭にあれば〜〜〜

//インスタンス作成
struct E44MenuSales: Identifiable {
    var id = UUID()
    var menu: String
    var amounts: Int
}

//データ配列をセット
let e44TempData: [E44MenuSales] = [
    E44MenuSales(menu: "🍎", amounts: 500),
    E44MenuSales(menu: "🍊", amounts: 400),
    E44MenuSales(menu: "🍌", amounts: 600),
]

struct E44ChartIdentifiableView: View {
    var body: some View {
        Chart(e44TempData){ fruits in
            AreaMark(
                x:.value("品目",fruits.menu),
                y:.value("個数",fruits.amounts)
            )
        }
    }
}

てな感じにして〜〜〜

さっきと結果は一緒〜〜〜

ForEachを使って〜〜〜

struct E44ChartIdentifiableForEachView: View {
    var body: some View {
        Chart{
            ForEach(e44TempData) { fruits in
                AreaMark(
                    x:.value("品目",fruits.menu),
                    y:.value("個数",fruits.amounts)
                )
            }
        }
    }
}

みたいな感じでやっても、

結果は同じ

他のチャートとコンビネーション

struct E44CombiningChartsView: View {
    var body: some View {
        Chart(e44TempData){ fruits in
            RectangleMark(
                x: .value("品目", fruits.menu),
                y: .value("個数", fruits.amounts)
            )
            LineMark(
                x: .value("品目", fruits.menu),
                y: .value("個数", fruits.amounts)
            )
        }
    }
}

てな感じにすると、、、

てな感じ

もちろん

struct E44CombiningChartsView: View {
    var body: some View {
        Chart(e44TempData){ fruits in
//            RectangleMark(
//                x: .value("品目", fruits.menu),
//                y: .value("個数", fruits.amounts)
//            )
            LineMark(
                x: .value("品目", fruits.menu),
                y: .value("個数", fruits.amounts)
            )
        }
    }
}

てな感じにすると

折れ線グラフ〜〜〜

データ絞り込み〜〜〜

//インスタンス作成
struct E44MenuSalesMonths: Identifiable {
    var id = UUID()
    var menu: String
    var amounts: Int
    var month: String
}

//データ配列をセット
let e44TempDataMonthly: [E44MenuSalesMonths] = [
    E44MenuSalesMonths(menu: "🍎", amounts: 500,month: "4月"),
    E44MenuSalesMonths(menu: "🍊", amounts: 400,month: "4月"),
    E44MenuSalesMonths(menu: "🍌", amounts: 600,month: "4月"),
    E44MenuSalesMonths(menu: "🍎", amounts: 350,month: "5月"),
    E44MenuSalesMonths(menu: "🍊", amounts: 550,month: "5月"),
    E44MenuSalesMonths(menu: "🍌", amounts: 700,month: "5月"),
]

struct E44FilteringChartsView: View {
    var body: some View {
        Chart{
            ForEach(e44TempDataMonthly){ fruits in
                LineMark(
                    x: .value("品目", fruits.menu),
                    y: .value("個数",fruits.amounts )
                )
                .foregroundStyle(by: .value("月", fruits.month))
            }
        }
    }
}

てな感じで〜〜〜

ほほ

これをAreaMarkに変更するだけで〜〜〜

struct E44FilteringChartsView: View {
    var body: some View {
        Chart{
            ForEach(e44TempDataMonthly){ fruits in
                AreaMark(
                    x: .value("品目", fruits.menu),
                    y: .value("個数",fruits.amounts )
                )
                .foregroundStyle(by: .value("月", fruits.month))
            }
        }
    }
}
バナナ売れ行き恐るべし藁😝

LineMarkに戻して、ポイントマーカーを付けると〜〜〜

struct E44FilteringChartsView: View {
    var body: some View {
        Chart{
            ForEach(e44TempDataMonthly){ fruits in
                LineMark(
                    x: .value("品目", fruits.menu),
                    y: .value("個数",fruits.amounts )
                )
                .foregroundStyle(by: .value("月", fruits.month))
                .symbol(by: .value("月", fruits.month))
            }
        }
    }
}
てな感じ

6月を増やして〜〜〜

//データ配列をセット
let e44TempDataMonthly: [E44MenuSalesMonths] = [
    E44MenuSalesMonths(menu: "🍎", amounts: 500,month: "4月"),
    E44MenuSalesMonths(menu: "🍊", amounts: 400,month: "4月"),
    E44MenuSalesMonths(menu: "🍌", amounts: 600,month: "4月"),
    E44MenuSalesMonths(menu: "🍎", amounts: 350,month: "5月"),
    E44MenuSalesMonths(menu: "🍊", amounts: 550,month: "5月"),
    E44MenuSalesMonths(menu: "🍌", amounts: 700,month: "5月"),
    E44MenuSalesMonths(menu: "🍎", amounts: 890,month: "6月"),
    E44MenuSalesMonths(menu: "🍊", amounts: 550,month: "6月"),
    E44MenuSalesMonths(menu: "🍌", amounts: 650,month: "6月"),
]

ビューのコードは何も変更してないけど

てな感じ😍

チャート図の背景を変えたいのであれば〜〜〜

struct E44FilteringChartsView: View {
    var body: some View {
        Chart{
            ForEach(e44TempDataMonthly){ fruits in
                LineMark(
                    x: .value("品目", fruits.menu),
                    y: .value("個数",fruits.amounts )
                )
                .foregroundStyle(by: .value("月", fruits.month))
                .symbol(by: .value("月", fruits.month))
            }
        }
        .chartPlotStyle{ fruitsArea in
            fruitsArea.background(.gray.opacity(0.2))
        }
    }
}
アプリのグラフっぽい藁🤣
👉BIツールってこんな感じよね〜〜〜

ここでポイント②:補完設定を変更して遊ぶと、、、

  • cardinal

  • catmullRom

  • linear

  • monotone

  • stepCenter

  • stepEnd

  • stepStart

てのがあるらしい

struct E44InterpolationChartsView: View {
    var body: some View {
        Chart{
            ForEach(e44TempDataMonthly){ fruits in
                LineMark(
                    x: .value("品目", fruits.menu),
                    y: .value("個数",fruits.amounts )
                )
                .interpolationMethod(.cardinal)
                .foregroundStyle(by: .value("月", fruits.month))
                .symbol(by: .value("月", fruits.month))
            }
        }
        .chartPlotStyle{ fruitsArea in
            fruitsArea.background(.gray.opacity(0.2))
        }
    }
}

てな感じにすると、、、

てな感じ
.catmullRom
.linear
.monotone
.stepCenter
.stepStart
.stepEnd

以上。

面白いから色々、コードを変更したり、データを変更したりして動かしてみてね〜〜〜🕺

今回のまとめコード

import SwiftUI
import Charts

struct Essentials44ContentsView: View {
    var body: some View {
        ScrollView{
            E44ChartStandardView()
            E44ChartIdentifiableView()
            E44ChartIdentifiableForEachView()
            E44CombiningChartsView()
            E44FilteringChartsView()
            E44InterpolationChartsView()
        }
        .safeAreaPadding()
    }
}

//インスタンス作成
struct E44MenuSales: Identifiable {
    var id = UUID()
    var menu: String
    var amounts: Int
}

//インスタンス作成
struct E44MenuSalesMonths: Identifiable {
    var id = UUID()
    var menu: String
    var amounts: Int
    var month: String
}

//データ配列をセット
let e44TempData: [E44MenuSales] = [
    E44MenuSales(menu: "🍎", amounts: 500),
    E44MenuSales(menu: "🍊", amounts: 400),
    E44MenuSales(menu: "🍌", amounts: 600),
]

//データ配列をセット
let e44TempDataMonthly: [E44MenuSalesMonths] = [
    E44MenuSalesMonths(menu: "🍎", amounts: 500,month: "4月"),
    E44MenuSalesMonths(menu: "🍊", amounts: 400,month: "4月"),
    E44MenuSalesMonths(menu: "🍌", amounts: 600,month: "4月"),
    E44MenuSalesMonths(menu: "🍎", amounts: 350,month: "5月"),
    E44MenuSalesMonths(menu: "🍊", amounts: 550,month: "5月"),
    E44MenuSalesMonths(menu: "🍌", amounts: 700,month: "5月"),
    E44MenuSalesMonths(menu: "🍎", amounts: 890,month: "6月"),
    E44MenuSalesMonths(menu: "🍊", amounts: 550,month: "6月"),
    E44MenuSalesMonths(menu: "🍌", amounts: 650,month: "6月"),
]

struct E44ChartStandardView: View {
    var body: some View {
        Chart{
            AreaMark(
                x:PlottableValue.value("品目","🍎"),
                y:PlottableValue.value("個数",500)
            )
            AreaMark(
                x:PlottableValue.value("品目","🍊"),
                y:PlottableValue.value("個数",400)
            )
            AreaMark(
                x:PlottableValue.value("品目","🍌"),
                y:PlottableValue.value("個数",600)
            )
        }
    }
}

struct E44ChartIdentifiableView: View {
    var body: some View {
        Chart(e44TempData){ fruits in
            AreaMark(
                x:.value("品目",fruits.menu),
                y:.value("個数",fruits.amounts)
            )
        }
    }
}

struct E44ChartIdentifiableForEachView: View {
    var body: some View {
        Chart{
            ForEach(e44TempData) { fruits in
                AreaMark(
                    x:.value("品目",fruits.menu),
                    y:.value("個数",fruits.amounts)
                )
            }
        }
    }
}

struct E44CombiningChartsView: View {
    var body: some View {
        Chart(e44TempData){ fruits in
            RectangleMark(
                x: .value("品目", fruits.menu),
                y: .value("個数", fruits.amounts)
            )
            LineMark(
                x: .value("品目", fruits.menu),
                y: .value("個数", fruits.amounts)
            )
        }
    }
}

struct E44FilteringChartsView: View {
    var body: some View {
        Chart{
            ForEach(e44TempDataMonthly){ fruits in
                LineMark(
                    x: .value("品目", fruits.menu),
                    y: .value("個数",fruits.amounts )
                )
                .foregroundStyle(by: .value("月", fruits.month))
                .symbol(by: .value("月", fruits.month))
            }
        }
        .chartPlotStyle{ fruitsArea in
            fruitsArea.background(.gray.opacity(0.2))
        }
    }
}

struct E44InterpolationChartsView: View {
    var body: some View {
        Chart{
            ForEach(e44TempDataMonthly){ fruits in
                LineMark(
                    x: .value("品目", fruits.menu),
                    y: .value("個数",fruits.amounts )
                )
                .interpolationMethod(.stepEnd)
                .foregroundStyle(by: .value("月", fruits.month))
                .symbol(by: .value("月", fruits.month))
            }
        }
        .chartPlotStyle{ fruitsArea in
            fruitsArea.background(.gray.opacity(0.2))
        }
    }
}

#Preview {
    Essentials44ContensView()
}

Apple公式

さてと、次回は

チャートを使った実践例

第45章 SwiftUIチャートチュートリアル

をやってく〜〜〜

記事公開後、

いつもどおり、

でやった操作を〜〜〜

てな
てな
てなで
ホイ、完了🕺

サンプルコード

◾️Essentials44.swift

import SwiftUI
import Charts
import WebKit

//タイトル
let essentialsChapter44NavigationTitle = "第44章"
let essentialsChapter44Title = "第44章 SwiftUI Chartsを使ったプレゼンテーションデータ"
let essentialsChapter44SubTitle = "第44章 SwiftUI Chartsを使ったプレゼンテーションデータ"

//コード
let codeEssentials44 = """
struct Essentials44ContentsView: View {
    var body: some View {
        ScrollView{
            E44ChartStandardView()
            E44ChartIdentifiableView()
            E44ChartIdentifiableForEachView()
            E44CombiningChartsView()
            E44FilteringChartsView()
            E44InterpolationChartsView()
        }
        .safeAreaPadding()
    }
}

//インスタンス作成
struct E44MenuSales: Identifiable {
    var id = UUID()
    var menu: String
    var amounts: Int
}

//インスタンス作成
struct E44MenuSalesMonths: Identifiable {
    var id = UUID()
    var menu: String
    var amounts: Int
    var month: String
}

//データ配列をセット
let e44TempData: [E44MenuSales] = [
    E44MenuSales(menu: "🍎", amounts: 500),
    E44MenuSales(menu: "🍊", amounts: 400),
    E44MenuSales(menu: "🍌", amounts: 600),
]

//データ配列をセット
let e44TempDataMonthly: [E44MenuSalesMonths] = [
    E44MenuSalesMonths(menu: "🍎", amounts: 500,month: "4月"),
    E44MenuSalesMonths(menu: "🍊", amounts: 400,month: "4月"),
    E44MenuSalesMonths(menu: "🍌", amounts: 600,month: "4月"),
    E44MenuSalesMonths(menu: "🍎", amounts: 350,month: "5月"),
    E44MenuSalesMonths(menu: "🍊", amounts: 550,month: "5月"),
    E44MenuSalesMonths(menu: "🍌", amounts: 700,month: "5月"),
    E44MenuSalesMonths(menu: "🍎", amounts: 890,month: "6月"),
    E44MenuSalesMonths(menu: "🍊", amounts: 550,month: "6月"),
    E44MenuSalesMonths(menu: "🍌", amounts: 650,month: "6月"),
]

struct E44ChartStandardView: View {
    var body: some View {
        Chart{
            AreaMark(
                x:PlottableValue.value("品目","🍎"),
                y:PlottableValue.value("個数",500)
            )
            AreaMark(
                x:PlottableValue.value("品目","🍊"),
                y:PlottableValue.value("個数",400)
            )
            AreaMark(
                x:PlottableValue.value("品目","🍌"),
                y:PlottableValue.value("個数",600)
            )
        }
    }
}

struct E44ChartIdentifiableView: View {
    var body: some View {
        Chart(e44TempData){ fruits in
            AreaMark(
                x:.value("品目",fruits.menu),
                y:.value("個数",fruits.amounts)
            )
        }
    }
}

struct E44ChartIdentifiableForEachView: View {
    var body: some View {
        Chart{
            ForEach(e44TempData) { fruits in
                AreaMark(
                    x:.value("品目",fruits.menu),
                    y:.value("個数",fruits.amounts)
                )
            }
        }
    }
}

struct E44CombiningChartsView: View {
    var body: some View {
        Chart(e44TempData){ fruits in
            RectangleMark(
                x: .value("品目", fruits.menu),
                y: .value("個数", fruits.amounts)
            )
            LineMark(
                x: .value("品目", fruits.menu),
                y: .value("個数", fruits.amounts)
            )
        }
    }
}

struct E44FilteringChartsView: View {
    var body: some View {
        Chart{
            ForEach(e44TempDataMonthly){ fruits in
                LineMark(
                    x: .value("品目", fruits.menu),
                    y: .value("個数",fruits.amounts )
                )
                .foregroundStyle(by: .value("月", fruits.month))
                .symbol(by: .value("月", fruits.month))
            }
        }
        .chartPlotStyle{ fruitsArea in
            fruitsArea.background(.gray.opacity(0.2))
        }
    }
}

struct E44InterpolationChartsView: View {
    var body: some View {
        Chart{
            ForEach(e44TempDataMonthly){ fruits in
                LineMark(
                    x: .value("品目", fruits.menu),
                    y: .value("個数",fruits.amounts )
                )
                .interpolationMethod(.stepEnd)
                .foregroundStyle(by: .value("月", fruits.month))
                .symbol(by: .value("月", fruits.month))
            }
        }
        .chartPlotStyle{ fruitsArea in
            fruitsArea.background(.gray.opacity(0.2))
        }
    }
}

#Preview {
    Essentials44ContentsView()
}
"""

//ポイント
let pointEssentials44 = """
◆①SwiftUIのChartsフレームワーク
・AreaMark
・BarMark
・LineMark
・PointMark
・RectangleMark
・RuleMark

◆②補完設定
・cardinal
・catmullRom
・linear
・monotone
・stepCenter
・stepEnd
・stepStart
"""

//URL
let urlEssentials44 = "https://note.com/m_kakudo/n/nef5e13a3746d"

//ビュー管理構造体
struct ListiOSApp17DevelopmentEssentialsCh44: Identifiable {
    var id: Int
    var title: String
    var view: ViewEnumiOSApp17DevelopmentEssentialsCh44
}
//遷移先の画面を格納する列挙型
enum ViewEnumiOSApp17DevelopmentEssentialsCh44{
    case Sec1
}
//各項目に表示するリスト項目
let dataiOSApp17DevelopmentEssentialsCh44: [ListiOSApp17DevelopmentEssentialsCh44] = [
    ListiOSApp17DevelopmentEssentialsCh44(id: 1, title: essentialsChapter44SubTitle, view: .Sec1),
]
struct iOSApp17DevelopmentEssentialsCh44: View {
    var body: some View {
        VStack {
            Divider()
            List (dataiOSApp17DevelopmentEssentialsCh44) { data in
                self.containedViewiOSApp17DevelopmentEssentialsCh44(dataiOSApp17DevelopmentEssentialsCh44: data)
            }
            .edgesIgnoringSafeArea([.bottom])
        }
        .navigationTitle(essentialsChapter44NavigationTitle)
        .navigationBarTitleDisplayMode(.inline)
    }
    //タップ後に遷移先へ遷移させる関数
    func containedViewiOSApp17DevelopmentEssentialsCh44(dataiOSApp17DevelopmentEssentialsCh44: ListiOSApp17DevelopmentEssentialsCh44) -> AnyView {
        switch dataiOSApp17DevelopmentEssentialsCh44.view {
        case .Sec1:
            return AnyView(NavigationLink (destination: Essentials44()) {
                Text(dataiOSApp17DevelopmentEssentialsCh44.title)
            })
        }
    }
}
#Preview {
    iOSApp17DevelopmentEssentialsCh44()
}

struct Essentials44: View {
    var body: some View {
        VStack{
            TabView {
                Essentials44ContentsView()
                    .tabItem {
                        Image(systemName: contentsImageTab)
                        Text(contentsTextTab)
                    }
                Essentials44Code()
                    .tabItem {
                        Image(systemName: codeImageTab)
                        Text(codeTextTab)
                    }
                Essentials44Points()
                    .tabItem {
                        Image(systemName: pointImageTab)
                        Text(pointTextTab)
                    }
                Essentials44WEB()
                    .tabItem {
                        Image(systemName: webImageTab)
                        Text(webTextTab)
                    }
            }
        }
    }
}
#Preview {
    Essentials44()
}

struct Essentials44Code: View {
    var body: some View {
        ScrollView{
            Text(codeEssentials44)
        }
    }
}
#Preview {
    Essentials44Code()
}
struct Essentials44Points: View {
    var body: some View {
        ScrollView{
            Text(pointEssentials44)
        }
    }
}
#Preview {
    Essentials44Points()
}
struct Essentials44WebView: UIViewRepresentable {
    let searchURL: URL
    func makeUIView(context: Context) -> WKWebView {
        let view = WKWebView()
        let request = URLRequest(url: searchURL)
        view.load(request)
        return view
    }
    func updateUIView(_ uiView: WKWebView, context: Context) {
        
    }
}
struct Essentials44WEB: View {
    private var url:URL = URL(string: urlEssentials44)!
    var body: some View {Essentials44WebView(searchURL: url)
    }
}
#Preview {
    Essentials44WEB()
}

struct Essentials44ContentsView: View {
    var body: some View {
        ScrollView{
            E44ChartStandardView()
            E44ChartIdentifiableView()
            E44ChartIdentifiableForEachView()
            E44CombiningChartsView()
            E44FilteringChartsView()
            E44InterpolationChartsView()
        }
        .safeAreaPadding()
    }
}

//インスタンス作成
struct E44MenuSales: Identifiable {
    var id = UUID()
    var menu: String
    var amounts: Int
}

//インスタンス作成
struct E44MenuSalesMonths: Identifiable {
    var id = UUID()
    var menu: String
    var amounts: Int
    var month: String
}

//データ配列をセット
let e44TempData: [E44MenuSales] = [
    E44MenuSales(menu: "🍎", amounts: 500),
    E44MenuSales(menu: "🍊", amounts: 400),
    E44MenuSales(menu: "🍌", amounts: 600),
]

//データ配列をセット
let e44TempDataMonthly: [E44MenuSalesMonths] = [
    E44MenuSalesMonths(menu: "🍎", amounts: 500,month: "4月"),
    E44MenuSalesMonths(menu: "🍊", amounts: 400,month: "4月"),
    E44MenuSalesMonths(menu: "🍌", amounts: 600,month: "4月"),
    E44MenuSalesMonths(menu: "🍎", amounts: 350,month: "5月"),
    E44MenuSalesMonths(menu: "🍊", amounts: 550,month: "5月"),
    E44MenuSalesMonths(menu: "🍌", amounts: 700,month: "5月"),
    E44MenuSalesMonths(menu: "🍎", amounts: 890,month: "6月"),
    E44MenuSalesMonths(menu: "🍊", amounts: 550,month: "6月"),
    E44MenuSalesMonths(menu: "🍌", amounts: 650,month: "6月"),
]

struct E44ChartStandardView: View {
    var body: some View {
        Chart{
            AreaMark(
                x:PlottableValue.value("品目","🍎"),
                y:PlottableValue.value("個数",500)
            )
            AreaMark(
                x:PlottableValue.value("品目","🍊"),
                y:PlottableValue.value("個数",400)
            )
            AreaMark(
                x:PlottableValue.value("品目","🍌"),
                y:PlottableValue.value("個数",600)
            )
        }
    }
}

struct E44ChartIdentifiableView: View {
    var body: some View {
        Chart(e44TempData){ fruits in
            AreaMark(
                x:.value("品目",fruits.menu),
                y:.value("個数",fruits.amounts)
            )
        }
    }
}

struct E44ChartIdentifiableForEachView: View {
    var body: some View {
        Chart{
            ForEach(e44TempData) { fruits in
                AreaMark(
                    x:.value("品目",fruits.menu),
                    y:.value("個数",fruits.amounts)
                )
            }
        }
    }
}

struct E44CombiningChartsView: View {
    var body: some View {
        Chart(e44TempData){ fruits in
            RectangleMark(
                x: .value("品目", fruits.menu),
                y: .value("個数", fruits.amounts)
            )
            LineMark(
                x: .value("品目", fruits.menu),
                y: .value("個数", fruits.amounts)
            )
        }
    }
}

struct E44FilteringChartsView: View {
    var body: some View {
        Chart{
            ForEach(e44TempDataMonthly){ fruits in
                LineMark(
                    x: .value("品目", fruits.menu),
                    y: .value("個数",fruits.amounts )
                )
                .foregroundStyle(by: .value("月", fruits.month))
                .symbol(by: .value("月", fruits.month))
            }
        }
        .chartPlotStyle{ fruitsArea in
            fruitsArea.background(.gray.opacity(0.2))
        }
    }
}

struct E44InterpolationChartsView: View {
    var body: some View {
        Chart{
            ForEach(e44TempDataMonthly){ fruits in
                LineMark(
                    x: .value("品目", fruits.menu),
                    y: .value("個数",fruits.amounts )
                )
                .interpolationMethod(.stepEnd)
                .foregroundStyle(by: .value("月", fruits.month))
                .symbol(by: .value("月", fruits.month))
            }
        }
        .chartPlotStyle{ fruitsArea in
            fruitsArea.background(.gray.opacity(0.2))
        }
    }
}

#Preview {
    Essentials44ContentsView()
}

◾️EssentialsMenu.swift

//フレームワーク
import SwiftUI
import WebKit

//ビュー管理構造体
struct ListiOSApp17DevelopmentEssentials: Identifiable {
    var id: Int
    var title: String
    var view: ViewEnumiOSApp17DevelopmentEssentials
}
//遷移先の画面を格納する列挙型
enum ViewEnumiOSApp17DevelopmentEssentials {
    case Ch1
    //じっくり13で追加
    case Ch2
    //じっくり14で追加
    case Ch3
    //じっくり15で追加
    case Ch4
    //じっくり16で追加
    case Ch5
    //じっくり17で追加
    case Ch6
    //じっくり18で追加
    case Ch7
    //じっくり19で追加
    case Ch8
    //じっくり20、21で追加
    case Ch9
    //じっくり22、23で追加
    case Ch10
    //じっくり24で追加
    case Ch11
    //じっくり25で追加
    case Ch12
    //じっくり26で追加
    case Ch13
    //じっくり27,28で追加
    case Ch14
    //じっくり29で追加
    case Ch15
    //じっくり31で追加
    case Ch16
    //じっくり32で追加
    case Ch17
    //じっくり33で追加
    case Ch18
    //じっくり34で追加
    case Ch19
    //じっくり35で追加
    case Ch20
    //じっくり36で追加
    case Ch21
    //じっくり37で追加
    case Ch22
    //じっくり40で追加
    case Ch23
    //じっくり41で追加
    case Ch24
    //じっくり43で追加
    case Ch25
    //じっくり44で追加
    case Ch26
    //じっくり45で追加
    case Ch27
    //じっくり46で追加
    case Ch28
    //じっくり47で追加
    case Ch29
    //じっくり48で追加
    case Ch30
    //じっくり49で追加
    case Ch31
    //じっくり50で追加
    case Ch32
    //じっくり51で追加
    case Ch33
    //じっくり52で追加
    case Ch34
    //じっくり53で追加
    case Ch35
    //じっくり54で追加
    case Ch36
    //じっくり55で追加
    case Ch37
    //じっくり56で追加
    case Ch38
    //じっくり57で追加
    case Ch39
    //じっくり58で追加
    case Ch40
    //じっくり59で追加
    case Ch41
    //じっくり60で追加
    case Ch42
    //じっくり61で追加
    case Ch43
    //じっくり62で追加
    case Ch44
}
//各項目に表示する文字列
let dataiOSApp17DevelopmentEssentials: [ListiOSApp17DevelopmentEssentials] = [
    ListiOSApp17DevelopmentEssentials(id: 1, title: essentialsChapter1Title, view: .Ch1),
    //じっくり13で追加
    ListiOSApp17DevelopmentEssentials(id: 2, title: essentialsChapter2Title, view: .Ch2),
    //じっくり13で追加
    ListiOSApp17DevelopmentEssentials(id: 3, title: essentialsChapter3Title, view: .Ch3),
    //じっくり15で追加
    ListiOSApp17DevelopmentEssentials(id: 4, title: essentialsChapter4Title, view: .Ch4),
    //じっくり16で追加
    ListiOSApp17DevelopmentEssentials(id: 5, title: essentialsChapter5Title, view: .Ch5),
    //じっくり17で追加
    ListiOSApp17DevelopmentEssentials(id: 6, title: essentialsChapter6Title, view: .Ch6),
    //じっくり18で追加
    ListiOSApp17DevelopmentEssentials(id: 7, title: essentialsChapter7Title, view: .Ch7),
    //じっくり19で追加
    ListiOSApp17DevelopmentEssentials(id: 8, title: essentialsChapter8Title, view: .Ch8),
    //じっくり20、21で追加
    ListiOSApp17DevelopmentEssentials(id: 9, title: essentialsChapter9Title, view: .Ch9),
    //じっくり22、23で追加
    ListiOSApp17DevelopmentEssentials(id: 10, title: essentialsChapter10Title, view: .Ch10),
    //じっくり24で追加
    ListiOSApp17DevelopmentEssentials(id: 11, title: essentialsChapter11Title, view: .Ch11),
    //じっくり25で追加
    ListiOSApp17DevelopmentEssentials(id: 12, title: essentialsChapter12Title, view: .Ch12),
    //じっくり26で追加
    ListiOSApp17DevelopmentEssentials(id: 13, title: essentialsChapter13Title, view: .Ch13),
    //じっくり27,28で追加
    ListiOSApp17DevelopmentEssentials(id: 14, title: essentialsChapter14Title, view: .Ch14),
    //じっくり29で追加
    ListiOSApp17DevelopmentEssentials(id: 15, title: essentialsChapter15Title, view: .Ch15),
    //じっくり31で追加
    ListiOSApp17DevelopmentEssentials(id: 16, title: essentialsChapter16Title, view: .Ch16),
    //じっくり32で追加
    ListiOSApp17DevelopmentEssentials(id: 17, title: essentialsChapter17Title, view: .Ch17),
    //じっくり33で追加
    ListiOSApp17DevelopmentEssentials(id: 18, title: essentialsChapter18Title, view: .Ch18),
    //じっくり34で追加
    ListiOSApp17DevelopmentEssentials(id: 19, title: essentialsChapter19Title, view: .Ch19),
    //じっくり35で追加
    ListiOSApp17DevelopmentEssentials(id: 20, title: essentialsChapter20Title, view: .Ch20),
    //じっくり36で追加
    ListiOSApp17DevelopmentEssentials(id: 21, title: essentialsChapter21Title, view: .Ch21),
    //じっくり37で追加
    ListiOSApp17DevelopmentEssentials(id: 22, title: essentialsChapter22Title, view: .Ch22),
    //じっくり40で追加
    ListiOSApp17DevelopmentEssentials(id: 23, title: essentialsChapter23Title, view: .Ch23),
    //じっくり41で追加
    ListiOSApp17DevelopmentEssentials(id: 24, title: essentialsChapter24Title, view: .Ch24),
    //じっくり43で追加
    ListiOSApp17DevelopmentEssentials(id: 25, title: essentialsChapter25Title, view: .Ch25),
    //じっくり44で追加
    ListiOSApp17DevelopmentEssentials(id: 26, title: essentialsChapter26Title, view: .Ch26),
    //じっくり45で追加
    ListiOSApp17DevelopmentEssentials(id: 27, title: essentialsChapter27Title, view: .Ch27),
    //じっくり46で追加
    ListiOSApp17DevelopmentEssentials(id: 28, title: essentialsChapter28Title, view: .Ch28),
    //じっくり47で追加
    ListiOSApp17DevelopmentEssentials(id: 29, title: essentialsChapter29Title, view: .Ch29),
    //じっくり48で追加
    ListiOSApp17DevelopmentEssentials(id: 30, title: essentialsChapter30Title, view: .Ch30),
    //じっくり49で追加
    ListiOSApp17DevelopmentEssentials(id: 31, title: essentialsChapter31Title, view: .Ch31),
    //じっくり50で追加
    ListiOSApp17DevelopmentEssentials(id: 32, title: essentialsChapter32Title, view: .Ch32),
    //じっくり51で追加
    ListiOSApp17DevelopmentEssentials(id: 33, title: essentialsChapter33Title, view: .Ch33),
    //じっくり52で追加
    ListiOSApp17DevelopmentEssentials(id: 34, title: essentialsChapter34Title, view: .Ch34),
    //じっくり53で追加
    ListiOSApp17DevelopmentEssentials(id: 35, title: essentialsChapter35Title, view: .Ch35),
    //じっくり54で追加
    ListiOSApp17DevelopmentEssentials(id: 36, title: essentialsChapter36Title, view: .Ch36),
    //じっくり55で追加
    ListiOSApp17DevelopmentEssentials(id: 37, title: essentialsChapter37Title, view: .Ch37),
    //じっくり56で追加
    ListiOSApp17DevelopmentEssentials(id: 38, title: essentialsChapter38Title, view: .Ch38),
    //じっくり57で追加
    ListiOSApp17DevelopmentEssentials(id: 39, title: essentialsChapter39Title, view: .Ch39),
    //じっくり58で追加
    ListiOSApp17DevelopmentEssentials(id: 40, title: essentialsChapter40Title, view: .Ch40),
    //じっくり59で追加
    ListiOSApp17DevelopmentEssentials(id: 41, title: essentialsChapter41Title, view: .Ch41),
    //じっくり60で追加
    ListiOSApp17DevelopmentEssentials(id: 42, title: essentialsChapter42Title, view: .Ch42),
    //じっくり61で追加
    ListiOSApp17DevelopmentEssentials(id: 43, title: essentialsChapter43Title, view: .Ch43),
    //じっくり62で追加
    ListiOSApp17DevelopmentEssentials(id: 44, title: essentialsChapter44Title, view: .Ch44),
]

struct iOSApp17DevelopmentEssentials: View {
    var body: some View {
        VStack {
            Divider()
            List (dataiOSApp17DevelopmentEssentials) { data in
                self.containedViewiOSApp17DevelopmentEssentials(dataiOSApp17DevelopmentEssentials: data)
            }
            .edgesIgnoringSafeArea([.bottom])
        }
        .navigationTitle("iOS開発の章目次")
        .navigationBarTitleDisplayMode(.inline)
    }
    //タップ後に遷移先へ遷移させる関数
    func containedViewiOSApp17DevelopmentEssentials(dataiOSApp17DevelopmentEssentials: ListiOSApp17DevelopmentEssentials) -> AnyView {
        switch dataiOSApp17DevelopmentEssentials.view {
        case .Ch1:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh1()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり13で追加
        case .Ch2:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh2()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり13で追加
        case .Ch3:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh3()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり15で追加
        case .Ch4:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh4()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり16で追加
        case .Ch5:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh5()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり17で追加
        case .Ch6:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh6()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり18で追加
        case .Ch7:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh7()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり19で追加
        case .Ch8:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh8()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり20、21で追加
        case .Ch9:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh9()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり22、23で追加
        case .Ch10:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh10()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり24で追加
        case .Ch11:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh11()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり25で追加
        case .Ch12:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh12()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり26で追加
        case .Ch13:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh13()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり27,28で追加
        case .Ch14:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh14()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり29で追加
        case .Ch15:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh15()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり31で追加
        case .Ch16:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh16()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり32で追加
        case .Ch17:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh17()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり33で追加
        case .Ch18:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh18()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり34で追加
        case .Ch19:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh19()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり35で追加
        case .Ch20:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh20()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり36で追加
        case .Ch21:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh21()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり37で追加
        case .Ch22:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh22()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり40で追加
        case .Ch23:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh23()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり41で追加
        case .Ch24:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh24()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり43で追加
        case .Ch25:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh25()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり44で追加
        case .Ch26:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh26()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり45で追加
        case .Ch27:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh27()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり46で追加
        case .Ch28:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh28()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり47で追加
        case .Ch29:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh29()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり48で追加
        case .Ch30:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh30()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり49で追加
        case .Ch31:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh31()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり50で追加
        case .Ch32:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh32()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり51で追加
        case .Ch33:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh33()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり52で追加
        case .Ch34:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh34()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり53で追加
        case .Ch35:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh35()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり54で追加
        case .Ch36:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh36()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり55で追加
        case .Ch37:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh37()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり56で追加
        case .Ch38:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh38()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり57で追加
        case .Ch39:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh39()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり58で追加
        case .Ch40:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh40()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり59で追加
        case .Ch41:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh41()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり60で追加
        case .Ch42:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh42()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり61で追加
        case .Ch43:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh43()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
            //じっくり62で追加
        case .Ch44:
            return AnyView(NavigationLink (destination: iOSApp17DevelopmentEssentialsCh44()) {
                Text(dataiOSApp17DevelopmentEssentials.title)
            })
        }
    }
}

#Preview {
    iOSApp17DevelopmentEssentials()
}

以上。

いいなと思ったら応援しよう!