0

Trying to create a Chart in ContentView. I keep seeing this error no matter how I try to construct it.

import Foundation
import SwiftUI
import Charts

struct StockView: View {
    var body: some View {
        Chart {
              BarMark(
                 x: .value("Department", "Finance"),
                 y: .value("Profit", 300000)
              )
        }
    }
}


#Preview {
    StockView()
}

Static method 'buildExpression' requires that 'Chart' conform to 'View'

rkatakam
  • 51
  • 6

1 Answers1

2

In my experiment minimum iOS16 or visionOS beta 1 and this code:

import SwiftUI
import Charts

struct ContentView: View {
    var body: some View {
        Chart {
            BarMark(
                x: .value("Department", "Finance"),
                y: .value("Profit", 300000)
            )
        }
    }
}

compile and run.

chart on Vision Pro Preview chart on iPhone simulator

svarrall
  • 8,545
  • 2
  • 27
  • 32
Dinox
  • 141
  • 1
  • 5