Open ClayPwr opened 3 years ago
hey, what exactly is your issue? I'm using Charts in a SwiftUI project just fine. Can you maybe post your code as source code instead of an image?
Hi, yeah you can take this Try with use widget preview, when I start preview on phone it work good.
` import Charts import SwiftUI import WidgetKit
struct Bar : UIViewRepresentable {
var entries : [BarChartDataEntry]
func makeUIView(context: Context) -> BarChartView {
let chart = BarChartView()
chart.data = addData()
return chart
}
func updateUIView(_ uiView: BarChartView, context: Context) {
uiView.data = addData()
}
func addData() -> BarChartData{
let data = BarChartData()
let dataSet = BarChartDataSet(entries: entries)
data.addDataSet(dataSet)
return data
}
typealias UIViewType = BarChartView
}
struct Bar_Previews: PreviewProvider {
static var previews: some View {
Bar(entries: [BarChartDataEntry(x: 1, y: 1)])
.previewContext(WidgetPreviewContext(family: .systemMedium))
}
}`
Hi, yeah you can take this Try with use widget preview, when I start preview on phone it work good.
I'm confused now. Is you problem just with the XCode SwiftUI preview or when actually running the app/widget? Your ticket description is not quite clear
@JanC sorry for that, problem in both situation when run app on simulator and on preview
@ClayPwr
UIKit views wrapped in UIViewRepresentable will not work in WidgetKit.
Source: https://developer.apple.com/forums/thread/653471?answerId=619627022#619627022
What did you do?
ℹ Tried to add charts inside widget
What did you expect to happen?
ℹ Saw a new chart
What happened instead?
ℹ Just yellow rectangle
Charts Environment
Charts version/Branch/Commit Number: 3.6.0 Xcode version: 12.4 Swift version: 5 Platform(s) running Charts: iOS widgets macOS version running Xcode: 11.2.3![Screen Shot 2021-05-20 at 7 24 37 PM](https://user-images.githubusercontent.com/25775867/119014825-0635e280-b9a1-11eb-9e0f-4b1e41255a62.png)