Swift Charts

RSS for tag

Visualize data with highly customizable charts across all Apple platforms using the compositional syntax of SwifUI.

Posts under Swift Charts tag

195 Posts

Post

Replies

Boosts

Views

Activity

Apple Charts framework not working with Xcode 14.3
Everything worked fine till 14.2, the moment we upgraded to 14.3 we started getting this errors for Charts. `Undefined symbol: _$s6Charts12ChartContentPAAE15foregroundStyle2byQrAA14PlottableValueVyqd__G_tAA0G0Rd__lFQOMQ Undefined symbol: _$s6Charts12ChartContentPAAE15foregroundStyleyQrqd__7SwiftUI05ShapeE0Rd__lF Undefined symbol: _$s6Charts12ChartContentPAAE15foregroundStyleyQrqd__7SwiftUI05ShapeE0Rd__lFQOMQ Undefined symbol: _$s6Charts12ChartContentPAAE8position2by4axis4spanQrAA14PlottableValueVyqd__G_7SwiftUI4AxisOSgAA13MarkDimensionVtAA0H0Rd__lF Undefined symbol: _$s6Charts12ChartContentPAAE8position2by4axis4spanQrAA14PlottableValueVyqd__G_7SwiftUI4AxisOSgAA13MarkDimensionVtAA0H0Rd__lFQOMQ Undefined symbol: _$s6Charts14AxisMarkPresetV9automaticACvgZ Undefined symbol: _$s6Charts14AxisMarkPresetVMa Undefined symbol: _$s6Charts14AxisMarkValuesV9automaticACvgZ Undefined symbol: _$s6Charts14AxisMarkValuesVMa Undefined symbol: _$s6Charts14AxisValueLabelV8centered6anchor05multiD9Alignment19collisionResolution12offsetsMarks11orientation17horizontalSpacing08verticalO0ACys5NeverOGSbSg_7SwiftUI9UnitPointVSgAP0H0VSgAA0bcd9CollisionJ0VAoA0bcD11OrientationV12CoreGraphics7CGFloatVSgA2_tcAMRszrlufC Undefined symbol: _$s6Charts14AxisValueLabelVMn Undefined symbol: _$s6Charts14AxisValueLabelVyxGAA0B4MarkAAMc Undefined symbol: _$s6Charts14PlottableValueV5valueyACyxGqd___xtSyRd__lFZ Undefined symbol: _$s6Charts14PlottableValueVMn Undefined symbol: _$s6Charts16AxisMarkPositionV9automaticACvgZ Undefined symbol: _$s6Charts16AxisMarkPositionVMa Undefined symbol: _$s6Charts18AnnotationPositionV3topACvgZ Undefined symbol: _$s6Charts18AnnotationPositionV6bottomACvgZ Undefined symbol: _$s6Charts18AnnotationPositionV8trailingACvgZ Undefined symbol: _$s6Charts18AnnotationPositionVMa Undefined symbol: _$s6Charts18BuilderConditionalV7StorageOMn Undefined symbol: _$s6Charts18BuilderConditionalVMn Undefined symbol: _$s6Charts18BuilderConditionalVyxq_GAA12ChartContentA2aERzAaER_rlMc Undefined symbol: _$s6Charts25AxisValueLabelOrientationV9automaticACvgZ Undefined symbol: _$s6Charts25AxisValueLabelOrientationVMa Undefined symbol: _$s6Charts33AxisValueLabelCollisionResolutionV9automaticACvgZ Undefined symbol: _$s6Charts33AxisValueLabelCollisionResolutionVMa Undefined symbol: _$s6Charts5ChartV7contentACyxGxyXE_tcfC Undefined symbol: _$s6Charts5ChartVMn Undefined symbol: _$s6Charts5ChartV_2id7contentACy7SwiftUI7ForEachVyqd__qd_0_qd_1_GGqd___s7KeyPathCy7ElementQyd__qd_0_Gqd_1_ANctcAIRszSkRd__SHRd_0_AA0B7ContentRd_1_r1_lufC Undefined symbol: _$s6Charts5ChartVyxG7SwiftUI4ViewAAMc Undefined symbol: _$s6Charts7BarMarkV1x1y5width6height8stackingAcA14PlottableValueVyxG_AJyq_GAA0C9DimensionVAnA0C14StackingMethodVtcAA0G0RzAaQR_r0_lufC Undefined symbol: _$s6Charts7BarMarkVAA12ChartContentAAWP Undefined symbol: _$s6Charts7BarMarkVMa Undefined symbol: _$s6Charts7BarMarkVMn Undefined symbol: _$s6Charts8AxisMarkPAAE15foregroundStyleyQrqd__7SwiftUI05ShapeE0Rd__lF Undefined symbol: _$s6Charts8AxisMarkPAAE15foregroundStyleyQrqd__7SwiftUI05ShapeE0Rd__lFQOMQ Undefined symbol: _$s6Charts8AxisMarkPAAE4fontyQr7SwiftUI4FontVSgF Undefined symbol: _$s6Charts8AxisMarkPAAE4fontyQr7SwiftUI4FontVSgFQOMQ Undefined symbol: _$s6Charts9AxisMarksV6preset8position6values7contentACyxGAA0B10MarkPresetV_AA0bH8PositionVAA0bH6ValuesVxyctcfC Undefined symbol: _$s6Charts9AxisMarksVMn Undefined symbol: _$s6Charts9AxisMarksVyxGAA0B7ContentAAMc Undefined symbol: _$s6Charts9ScaleTypeVMa Undefined symbol: _$s6Charts9ScaleTypeVMn Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartXAxis7contentQrqd__yXE_tAD11AxisContentRd__lF Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartXAxis7contentQrqd__yXE_tAD11AxisContentRd__lFQOMQ Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartXAxisyQrAA10VisibilityOF Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartXAxisyQrAA10VisibilityOFQOMQ Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartYAxis7contentQrqd__yXE_tAD11AxisContentRd__lF Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartYAxis7contentQrqd__yXE_tAD11AxisContentRd__lFQOMQ Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartYAxisyQrAA10VisibilityOF Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartYAxisyQrAA10VisibilityOFQOMQ Undefined symbol: _$s7SwiftUI4ViewP6ChartsE25chartForegroundStyleScale6domain5range4typeQrqd___qd_0_AD0H4TypeVSgtAD0H6DomainRd__AD0H5RangeRd_0_AA05ShapeG011VisualValueRpd_0_r0_lF Undefined symbol: _$s7SwiftUI4ViewP6ChartsE25chartForegroundStyleScale6domain5range4typeQrqd___qd_0_AD0H4TypeVSgtAD0H6DomainRd__AD0H5RangeRd_0_AA05ShapeG011VisualValueRpd_0_r0_lFQOMQ Undefined symbol: _$s7SwiftUI7ForEachV6Charts7Element_2IDQZRs_AD12ChartContentR0_s12IdentifiableAERpzrlE_7contentACyxq_q0_Gx_q0_AJctcfC Undefined symbol: _$s7SwiftUI7ForEachV6ChartsAD12ChartContentR0_rlE_2id7contentACyxq_q0_Gx_s7KeyPathCy7ElementQzq_Gq0_ALctcfC Undefined symbol: _$s7SwiftUI7ForEachVyxq_q0_G6Charts12ChartContentA2eFR0_rlMc Undefined symbol: _$sSS6Charts9PlottableAAWP Undefined symbol: _$sSayxG6Charts10ScaleRangeABMc Undefined symbol: _$sSayxG6Charts11ScaleDomainA2B9PlottableRzlMc Undefined symbol: _$sSd6Charts9PlottableAAWP Linker command failed with exit code 1 (use -v to see invocation)` Can some help me to move forward on this please
0
0
796
May ’23
I try to run function on another class, But have a suspicious nil in code.
Hello! I'm a newbie swift dev! I try to create a project recently, but I encountered strange problems often for no reason. I have a button to change pages, but my page uses UIViewContainer for page classification, If user will change page. They will touch button in UIViewContainer class "Home" for tell to viewController(the mastermind class of all page) for use change page function, after that page will change. I have some tools for try to use function in ViewController for test, and It worked! But the problem is this. I don't know how I use function over page. If now user is stay a HomeController. will have to command skip class for use function on viewController. I find this code for that, But have a error. Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value I don't know this is a program restrictions or code have a bug. I think when I use this code, I can call the function on viewController for change page. but have a error in function. yeah... in function. If base on that image. I have this bug in UIViewContoller class "MyClass"(It's can call the function in UIViewContoller when user touch button in ViewContainer). and have a bug in addChild(controllerTwo!). Have a way for fix? or have a way for use function on another class? I don't see how to do that on website and books. I don't know what this name of code. and thank you for answer! and so very sorry for my strange English. 😅
1
0
966
May ’23
Can't get Charts BarMark to resize with window
I have a Swift Charts bar chart that looks great when there is a narrow gap between vertical bars but not so good when gaps either get large or go away altogether. Have been trying to figure out how to make bars resize with window so that narrow gaps are maintained. Seems like this should work: BarMark( x: .value("Year", barSegment.age), y: .value("PercentSuccess", barSegment.percentage), width: MarkDimension.inset(CGFloat(10.0)) ) In practice, though, this just ends up producing fixed width bars. Have also tried: BarMark( x: .value("Year", barSegment.age), y: .value("PercentSuccess", barSegment.percentage), width: MarkDimension.ratio(CGFloat(0.9)) ) But this doesn't show bars at all, regardless of what argument I give to ratio. How do I get the effect that I want?
1
1
1.2k
May ’23
Swift Charts real time update LineMark is slow
Hello I'm currently working on a new gui in my App and I wanted to use the new Swift Charts Framework. It's very beautiful but I'm struggling with performance here. I want to draw a LineMark in realtime. I have code that create me a point every 25ms over a runtime of about 10 seconds. So I have round about 400 Samples which should drawn in realtime to the Chart so I can see the LineMark being drawn. On a first try I used a Binding to the Chart to update the Chart and after 2-3 seconds the ui becomes unresponsive and started lagging. I'm currently using an ObservableObject and the .drawingGroup modifier to improve the Performance. This Helps but it's not perfect. Is there a better way to increase the Performance or what's the way to have a realtime drawing line graph? Here's the Code I use: struct ChartView: View { @ObservedObject public var model = FNMeasurementModel() private let gradient = LinearGradient(gradient: Gradient (colors: [.mint.opacity(0.1),.mint.opacity(0.0)]), startPoint: .top, endPoint: .bottom) var body: some View { Chart() { ForEach(model.data) { item in LineMark( x: .value("Ratio", item.ratio ?? .zero), y: .value("Speed", item.speed ?? .zero) ) .interpolationMethod(.catmullRom) .foregroundStyle(.mint) AreaMark( x: .value("Ratio", item.ratio ?? .zero), y: .value("Speed", item.speed ?? .zero) ) .foregroundStyle(gradient) } } .chartXAxis{ AxisMarks(position: .bottom, values: stride(from: 0, to: 1.0, by: 0.2).map { $0 }) } .chartXScale(domain: 0...1.0) .chartYScale(domain: 0...100) .frame(height: 100) .padding(.vertical, 5) } } The ObservableObject class FNMeasurementModel: ObservableObject { @Published public var data: [FNMeasurementResult] = [] func append(_ sample: FNMeasurementResult) -> Void { data.append(sample) } func reset() -> Void { data.removeAll() } } My Result Type public class FNMeasurementResult: Identifiable { public var id: UUID = UUID() public var ratio: Double? public var speed: Double? public init(speed: Double? = nil, ratio: Double? = nil) { self.ratio = ratio self.speed = speed } }
1
0
2.7k
Apr ’23
Overlapping AreaMarks not working
I am trying to make a chart that looks like: Basically a couple overlapping range AreaMark's, a LineMark and a couple RuleMarks. However when I have two separate AreaMark's I get this: When one or the other of the AreaMark's ForEach loop is commented out it displays the proper graph. Its just the overlap of the two that is wonky. FYI - The top graph was generated by the SwiftUI Charts package on GitHub which we are trying to move away from. Thanks.
2
0
938
Apr ’23
How can I apply the modify my Swift Chart based on the ComplicationRenderingMode
For Apple Watch complications displayed on tinted faced, developers can use: @Environment(\.complicationRenderingMode) var renderingMode to see if the watch face is tinted. You can then use the .complicationForeground() modifier to set elements of the complication to match that tint color. (I appreciate that .complicationForeground() is now deprecated in favour of .widgetAccentable() but I believe the behaviour is the same). However, this can only be applied to a view I believe. I'd like to display a Swift Chart where only certain elements of the chart have the .complicationForeground() rather than the whole chart. For example, in one case I'd like the LineMark to pop with the tinted color of the complication whilst the rest of the complication get the gray default tint. Is there a way to do with with the current APIs? Thanks
2
0
1.5k
Apr ’23
Swift Charts Axis Adjustment
I am working on a Mac app that uses Swift Charts to visualize some data. I can initially plot the data fine. The problem is that I want the ability to "zoom" in on the data. to do this I change the range of the x or y axis using the following modifiers .chartXScale(domain: xMin...xMax) .chartYScale(domain: yMin...yMax) I use a drag gesture to change the values of xMin and xMax for example to zoom in on the data. This does have the effect that I want but the problem is it causes the line to start moving out of the chart area like show below. I don't understand why this is happening. I thought by changing the scale it would cause only the data that is visible on the chart to be displayed.
1
1
1.4k
Mar ’23
Swift Charts BarMark bar shape when stacked
Hi I'm trying to apply clip shape on a BarMark with stacked values and the result is that it's applying the shape for each stack instead for the whole bar. What I want to achieve: What I got: I noticed that corner radius is applied to the whole bar but just the top of it: Is there any way to get this capsule shape when stacked? My code is: enum Value: Int, Hashable, CaseIterable {     case ftb     case nb     case remaining     var color: Color {         switch self {         case .ftb:             return .tint1         case .nb:             return .tint2         case .ramaining:             return .gray4         }     } } @ViewBuilder var barChart: some View {         Chart {             ForEach(dates, id: \.self) { date in                 let incomeSummary = incomeSummaries.first(where: { $0.date?.inSameDay(as: date) == true })                 ForEach(Value.allCases, id: \.self) { value in                     barMark(for: value, date: date, incomeSummary: incomeSummary)                         .foregroundStyle(value.color)                 } //                .cornerRadius(20, style: .continuous) //                .clipShape(Capsule())             }         }         .chartXAxis {             AxisMarks(values: dates) { date in                 AxisValueLabel(format: .dateTime.weekday(), centered: true)             }         }         .chartYAxis {             AxisMarks { mark in                 AxisValueLabel()             }         }     } private func barMark(for value: Value, date: Date, incomeSummary: IncomeSummary?) -> BarMark {         let amount = amount(for: value, in: incomeSummary)         return BarMark(x: .value("WeekDay", date, unit: .day,                                  calendar: Calendar.localTime),                 y: .value("Income", amount))     } Another issue, I've noticed that when AxisValueLabel is centered the last bar looses its label, is it a bug?
0
3
1.7k
Mar ’23
SwiftCharts: How to clip data to specific range?
I found that can customise the range of the x and y axes. But my problem is that for line marks some data might just be outside the axes range. If I add .clipped to the chart that would limit it, but then it also clips off some of the axis marks. No Clipping: With Clipping: you see the green line go over the AxisValueLabel area and the topmost label is clipped off. One way I can imagine addressing this without enabling clipping is to create an interpolated value for values that are just outside the chart range so that the line ends exactly at the min/max.
5
2
2.8k
Mar ’23
Chart: How to achieve a specific X-axis (an awkward log scale)
I'm trying to determine how best to achieve a desired result within Swift Charts. I'm trying to make a sort-of "reversed" log chart. The use case here is for driving into the details of the percentiles from a series latency values stored within a histogram. The X axis percentile values I was hoping to achieve was something along the lines of: 10, 50, 90, 99, 99,9, 99.99, 99.999 With those values being fairly evenly distributed across the chart. If I look at this from an inverted sequence of: ( 1 - (some value) ).reversed() where the values are: 0.00001, 0.0001, 0.0001, 0.001, 0.01, 0.5, 0.1 But I've been struggling with how to start with those values, scale the X axis using a 1-value kind of setup, and then overlaying the values that are more human readable to achieve the end result. Any suggestions on how to tackle this scenario with customizing a chart axis?
1
0
2.1k
Mar ’23
Launch an animation when a value in picker changes
Hi, I have two charts on the page and you can switch between them with the picker. Can you please tell me how can I make them show with animation? I do not know how to start the animation when I change a chart in the picker. Thank you! struct ChartsView: View {     var stackedBarData: [ToyShape] = [         .init(type: "Cube", count: 0),         .init(type: "Sphere", count: 0),         .init(type: "Pyramid", count: 1),     ]     var charts = ["Bar chart", "Area chart"]     @State private var selectedChart = "Bar chart"     var body: some View {         VStack {             if selectedChart == "Bar chart" {                 Chart {                     ForEach(stackedBarData) { shape in                         BarMark(                             x: .value("Shape Type", shape.type),                             y: .value("Total Count", shape.count)                         )                     }                 }                 .padding(.vertical, 20)             } else if selectedChart == "Area chart" {                 Chart {                     ForEach(stackedBarData) { shape in                         AreaMark(                             x: .value("Shape Type", shape.type),                             y: .value("Total Count", shape.count)                         )                     }                 }                 .padding(.vertical, 20)             }             Picker("Select a chart", selection: $selectedChart) {                 ForEach(charts, id: \.self) {                     Text($0)                 }             }             .pickerStyle(.segmented)         }         .padding(16)     } }
0
0
995
Feb ’23
Trading charts tool integration
Hello developers, I'm currently working on an iOS application that requires trading chart functionality, and I'm looking for a solution that I can easily integrate into my app. I've heard about TradingView's charting and technical analysis tools, but I'm not sure if they offer a library that I can use. Can anyone recommend a charting tool that is easy to integrate into an iOS app? Ideally, the tool should offer real-time data streaming, support for multiple chart types, and customizable indicators and drawing tools. Any suggestions or recommendations would be greatly appreciated. Thank you!
0
0
809
Feb ’23
SwiftUI Charts - MTLTextureDescriptor has width (9649) greater than the maximum allowed size of 8192
Hi, SwiftUI Charts IOS 16.1 I get crash in the Simulator (tried iPhone or iPad). See console message below. The strange thing is that if I ran the same app on my iPhone 12, no crash. Thank you 2023-01-11 13:58:57.306324+1100 MyMoney[52429:14665675] Metal API Validation Enabled 2023-01-11 13:58:57.451214+1100 MyMoney[52429:14665675] [error] RBLayer: unable to create texture: BGRA8Unorm, [19057, 938] 2023-01-11 13:58:57.451426+1100 MyMoney[52429:14665675] [error] RBLayer: unable to create texture: BGRA8Unorm, [19057, 938] 2023-01-11 13:58:57.470351+1100 MyMoney[52429:14665675] -[MTLTextureDescriptorInternal validateWithDevice:], line 1344: error 'Texture Descriptor Validation MTLTextureDescriptor has width (9649) greater than the maximum allowed size of 8192. ' -[MTLTextureDescriptorInternal validateWithDevice:]:1344: failed assertion `Texture Descriptor Validation MTLTextureDescriptor has width (9649) greater than the maximum allowed size of 8192.
1
0
1.7k
Feb ’23
SwiftUI Charts Issue - Axis Marks
I'm having an issue with SwiftUI charts and was wondering if anyone knows of a solution or has also run into this. I've been trying to plot data for my app and the X axis does not show the dates and the Y axis only has axis marks 0-9. So, I tried to make another file instance to check what's going on. This is what I have import Charts import SwiftUI struct Exercise: Identifiable { let id = UUID() var dateCompleted: Date var reps: Int } struct ContentView: View { private var exerciseMaxRepsArray: [Exercise] = [] init() { // init dummy data for i in 0 ..< 20 { let date = Calendar.current.date(byAdding: .day, value: i, to: .now) ?? .now let rep = Int.random(in: 1...20) exerciseMaxRepsArray.append( Exercise(dateCompleted: date, reps: rep) ) } } var body: some View { GroupBox(label: Text("Daily Max Reps")) { Chart(exerciseMaxRepsArray) { e in LineMark(x: .value("Date", e.dateCompleted, unit: .day), y: .value("Reps", e.reps) ) } .chartYAxisLabel(position: .trailing, alignment: .center) { Text("Reps") } .chartXAxisLabel(position: .bottom, alignment: .center) { Text("Date") } } and this is the result: I've checked and the issue is not the frame. Has anyone else had this issue or have any clue what could be going on here?
1
0
2.2k
Feb ’23
Swift Charts use custom font for legend
We have a custom font we use through-out our app we've recently starting playing with Swift Charts but can't work out how to use our font in the chart legend easily. Currently we have a simple chart using the default .chartLegend(...). I've managed to use our font in the X-axis and Y-axis by creating our own labels using AxisValueLabel() {} However without making our own completely custom legend, is there a way to specify the font to use in the legend?
0
0
1.2k
Jan ’23
Charts: How do I position x axis value labels below the associated grid lines
I am working with the new Charts Framework. The axis value labels for the x axis are dates (mm/dd/yy). I have 5 vertical grid lines and am trying to get the dates to be centered below the associated grid line with no success. One additional problem is that the values are in an array that contains 5 dates but only the first 4 get displayed. Any solutions will be appreciated. Below is the code. struct LineChart: View { private var localArray: [TradingDayPrices] init(passedInArray: [TradingDayPrices]) { self.localArray = passedInArray } var body: some View { let minCloseValue: Double = localArray.map { $0.close }.min()! let maxCloseValue: Double = localArray.map { $0.close }.max()! let minDate: Date = localArray[0].timeStamp! let itemCount: Int = localArray.count - 1 let maxDate: Date = localArray[itemCount].timeStamp! Spacer() GroupBox (label: Text("VOO Closing Values For The Past Year") .font(.system(size: 20)) .fontWeight(.bold) .frame(width: 700, height: 50, alignment: .center)) { Chart { ForEach(localArray) { item in LineMark ( x: .value("TimeStamp", item.timeStamp!), y: .value("Close", item.close) ) .foregroundStyle(Color.blue) .lineStyle(StrokeStyle(lineWidth: 1.25)) } // end for each } // end chart .padding(50) .chartBackground { item in Color.white } .chartXAxisLabel(position: .bottom, alignment: .center) { Text("Date") .font(.system(size: 14)) .foregroundColor(Color.black) .frame(width: 50, height: 35, alignment: .bottom) } .chartYAxisLabel(position: .leading, alignment: .center, spacing: 0) { Text("Closing Values") .font(.system(size: 14)) .foregroundColor(Color.black) } .chartXAxis { AxisMarks (values: GetXAxisLabels(min: minDate, max: maxDate)) { value in AxisGridLine(stroke: StrokeStyle(lineWidth: 0.5)) .foregroundStyle(Color.gray) AxisValueLabel() { if let localDate = value.as(Date.self) { let formattedDate = dateToStringFormatter.string(from: localDate) Text(formattedDate) .font(.system(size: 12)) .foregroundColor(Color.black) } } // end axis value label } // end axis marks } // end chart x axis .chartYAxis { AxisMarks (position: .leading, values: GetYAxisLabels(min: minCloseValue, max: maxCloseValue)) { value in AxisGridLine(stroke: StrokeStyle(lineWidth: 0.5)) .foregroundStyle(Color.gray) AxisValueLabel() { if let localValue = value.as(Double.self) { let formattedValue = String(format: "$%.2f", localValue) Text(formattedValue) .font(.system(size: 12)) .foregroundColor(Color.black) } } } // end axis marks } // end chart y axis .chartXScale(domain: minDate...maxDate) .chartYScale(domain: minCloseValue...maxCloseValue) .frame(width: 700, height: 700, alignment: .center) } // end group box } // end of body } // end of structure func GetXAxisLabels(min: Date, max: Date) -> [Date] { var xLabels: [Date] = [] let increment: Int = 90 for i in 0...3 { let value = Calendar.current.date(byAdding: DateComponents(day: (i * increment)), to: min)! xLabels.append(value) } xLabels.append(max) print("\(xLabels)") return xLabels } func GetYAxisLabels(min: Double, max: Double) -> [Double] { var yLabels: [Double] = [] let increment: Double = (max - min) / 4 for i in 0...3 { let value = min + (Double(i) * increment) yLabels.append(value) } yLabels.append(max) return yLabels } let dateToStringFormatter: DateFormatter = { let result = DateFormatter() result.dateFormat = "MM/dd/yy" return result }()
2
1
4k
Jan ’23
Apple Charts framework not working with Xcode 14.3
Everything worked fine till 14.2, the moment we upgraded to 14.3 we started getting this errors for Charts. `Undefined symbol: _$s6Charts12ChartContentPAAE15foregroundStyle2byQrAA14PlottableValueVyqd__G_tAA0G0Rd__lFQOMQ Undefined symbol: _$s6Charts12ChartContentPAAE15foregroundStyleyQrqd__7SwiftUI05ShapeE0Rd__lF Undefined symbol: _$s6Charts12ChartContentPAAE15foregroundStyleyQrqd__7SwiftUI05ShapeE0Rd__lFQOMQ Undefined symbol: _$s6Charts12ChartContentPAAE8position2by4axis4spanQrAA14PlottableValueVyqd__G_7SwiftUI4AxisOSgAA13MarkDimensionVtAA0H0Rd__lF Undefined symbol: _$s6Charts12ChartContentPAAE8position2by4axis4spanQrAA14PlottableValueVyqd__G_7SwiftUI4AxisOSgAA13MarkDimensionVtAA0H0Rd__lFQOMQ Undefined symbol: _$s6Charts14AxisMarkPresetV9automaticACvgZ Undefined symbol: _$s6Charts14AxisMarkPresetVMa Undefined symbol: _$s6Charts14AxisMarkValuesV9automaticACvgZ Undefined symbol: _$s6Charts14AxisMarkValuesVMa Undefined symbol: _$s6Charts14AxisValueLabelV8centered6anchor05multiD9Alignment19collisionResolution12offsetsMarks11orientation17horizontalSpacing08verticalO0ACys5NeverOGSbSg_7SwiftUI9UnitPointVSgAP0H0VSgAA0bcd9CollisionJ0VAoA0bcD11OrientationV12CoreGraphics7CGFloatVSgA2_tcAMRszrlufC Undefined symbol: _$s6Charts14AxisValueLabelVMn Undefined symbol: _$s6Charts14AxisValueLabelVyxGAA0B4MarkAAMc Undefined symbol: _$s6Charts14PlottableValueV5valueyACyxGqd___xtSyRd__lFZ Undefined symbol: _$s6Charts14PlottableValueVMn Undefined symbol: _$s6Charts16AxisMarkPositionV9automaticACvgZ Undefined symbol: _$s6Charts16AxisMarkPositionVMa Undefined symbol: _$s6Charts18AnnotationPositionV3topACvgZ Undefined symbol: _$s6Charts18AnnotationPositionV6bottomACvgZ Undefined symbol: _$s6Charts18AnnotationPositionV8trailingACvgZ Undefined symbol: _$s6Charts18AnnotationPositionVMa Undefined symbol: _$s6Charts18BuilderConditionalV7StorageOMn Undefined symbol: _$s6Charts18BuilderConditionalVMn Undefined symbol: _$s6Charts18BuilderConditionalVyxq_GAA12ChartContentA2aERzAaER_rlMc Undefined symbol: _$s6Charts25AxisValueLabelOrientationV9automaticACvgZ Undefined symbol: _$s6Charts25AxisValueLabelOrientationVMa Undefined symbol: _$s6Charts33AxisValueLabelCollisionResolutionV9automaticACvgZ Undefined symbol: _$s6Charts33AxisValueLabelCollisionResolutionVMa Undefined symbol: _$s6Charts5ChartV7contentACyxGxyXE_tcfC Undefined symbol: _$s6Charts5ChartVMn Undefined symbol: _$s6Charts5ChartV_2id7contentACy7SwiftUI7ForEachVyqd__qd_0_qd_1_GGqd___s7KeyPathCy7ElementQyd__qd_0_Gqd_1_ANctcAIRszSkRd__SHRd_0_AA0B7ContentRd_1_r1_lufC Undefined symbol: _$s6Charts5ChartVyxG7SwiftUI4ViewAAMc Undefined symbol: _$s6Charts7BarMarkV1x1y5width6height8stackingAcA14PlottableValueVyxG_AJyq_GAA0C9DimensionVAnA0C14StackingMethodVtcAA0G0RzAaQR_r0_lufC Undefined symbol: _$s6Charts7BarMarkVAA12ChartContentAAWP Undefined symbol: _$s6Charts7BarMarkVMa Undefined symbol: _$s6Charts7BarMarkVMn Undefined symbol: _$s6Charts8AxisMarkPAAE15foregroundStyleyQrqd__7SwiftUI05ShapeE0Rd__lF Undefined symbol: _$s6Charts8AxisMarkPAAE15foregroundStyleyQrqd__7SwiftUI05ShapeE0Rd__lFQOMQ Undefined symbol: _$s6Charts8AxisMarkPAAE4fontyQr7SwiftUI4FontVSgF Undefined symbol: _$s6Charts8AxisMarkPAAE4fontyQr7SwiftUI4FontVSgFQOMQ Undefined symbol: _$s6Charts9AxisMarksV6preset8position6values7contentACyxGAA0B10MarkPresetV_AA0bH8PositionVAA0bH6ValuesVxyctcfC Undefined symbol: _$s6Charts9AxisMarksVMn Undefined symbol: _$s6Charts9AxisMarksVyxGAA0B7ContentAAMc Undefined symbol: _$s6Charts9ScaleTypeVMa Undefined symbol: _$s6Charts9ScaleTypeVMn Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartXAxis7contentQrqd__yXE_tAD11AxisContentRd__lF Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartXAxis7contentQrqd__yXE_tAD11AxisContentRd__lFQOMQ Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartXAxisyQrAA10VisibilityOF Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartXAxisyQrAA10VisibilityOFQOMQ Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartYAxis7contentQrqd__yXE_tAD11AxisContentRd__lF Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartYAxis7contentQrqd__yXE_tAD11AxisContentRd__lFQOMQ Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartYAxisyQrAA10VisibilityOF Undefined symbol: _$s7SwiftUI4ViewP6ChartsE10chartYAxisyQrAA10VisibilityOFQOMQ Undefined symbol: _$s7SwiftUI4ViewP6ChartsE25chartForegroundStyleScale6domain5range4typeQrqd___qd_0_AD0H4TypeVSgtAD0H6DomainRd__AD0H5RangeRd_0_AA05ShapeG011VisualValueRpd_0_r0_lF Undefined symbol: _$s7SwiftUI4ViewP6ChartsE25chartForegroundStyleScale6domain5range4typeQrqd___qd_0_AD0H4TypeVSgtAD0H6DomainRd__AD0H5RangeRd_0_AA05ShapeG011VisualValueRpd_0_r0_lFQOMQ Undefined symbol: _$s7SwiftUI7ForEachV6Charts7Element_2IDQZRs_AD12ChartContentR0_s12IdentifiableAERpzrlE_7contentACyxq_q0_Gx_q0_AJctcfC Undefined symbol: _$s7SwiftUI7ForEachV6ChartsAD12ChartContentR0_rlE_2id7contentACyxq_q0_Gx_s7KeyPathCy7ElementQzq_Gq0_ALctcfC Undefined symbol: _$s7SwiftUI7ForEachVyxq_q0_G6Charts12ChartContentA2eFR0_rlMc Undefined symbol: _$sSS6Charts9PlottableAAWP Undefined symbol: _$sSayxG6Charts10ScaleRangeABMc Undefined symbol: _$sSayxG6Charts11ScaleDomainA2B9PlottableRzlMc Undefined symbol: _$sSd6Charts9PlottableAAWP Linker command failed with exit code 1 (use -v to see invocation)` Can some help me to move forward on this please
Replies
0
Boosts
0
Views
796
Activity
May ’23
I try to run function on another class, But have a suspicious nil in code.
Hello! I'm a newbie swift dev! I try to create a project recently, but I encountered strange problems often for no reason. I have a button to change pages, but my page uses UIViewContainer for page classification, If user will change page. They will touch button in UIViewContainer class "Home" for tell to viewController(the mastermind class of all page) for use change page function, after that page will change. I have some tools for try to use function in ViewController for test, and It worked! But the problem is this. I don't know how I use function over page. If now user is stay a HomeController. will have to command skip class for use function on viewController. I find this code for that, But have a error. Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value I don't know this is a program restrictions or code have a bug. I think when I use this code, I can call the function on viewController for change page. but have a error in function. yeah... in function. If base on that image. I have this bug in UIViewContoller class "MyClass"(It's can call the function in UIViewContoller when user touch button in ViewContainer). and have a bug in addChild(controllerTwo!). Have a way for fix? or have a way for use function on another class? I don't see how to do that on website and books. I don't know what this name of code. and thank you for answer! and so very sorry for my strange English. 😅
Replies
1
Boosts
0
Views
966
Activity
May ’23
Can't get Charts BarMark to resize with window
I have a Swift Charts bar chart that looks great when there is a narrow gap between vertical bars but not so good when gaps either get large or go away altogether. Have been trying to figure out how to make bars resize with window so that narrow gaps are maintained. Seems like this should work: BarMark( x: .value("Year", barSegment.age), y: .value("PercentSuccess", barSegment.percentage), width: MarkDimension.inset(CGFloat(10.0)) ) In practice, though, this just ends up producing fixed width bars. Have also tried: BarMark( x: .value("Year", barSegment.age), y: .value("PercentSuccess", barSegment.percentage), width: MarkDimension.ratio(CGFloat(0.9)) ) But this doesn't show bars at all, regardless of what argument I give to ratio. How do I get the effect that I want?
Replies
1
Boosts
1
Views
1.2k
Activity
May ’23
problem is solved
problem is solved
Replies
0
Boosts
0
Views
573
Activity
Apr ’23
Swift Charts real time update LineMark is slow
Hello I'm currently working on a new gui in my App and I wanted to use the new Swift Charts Framework. It's very beautiful but I'm struggling with performance here. I want to draw a LineMark in realtime. I have code that create me a point every 25ms over a runtime of about 10 seconds. So I have round about 400 Samples which should drawn in realtime to the Chart so I can see the LineMark being drawn. On a first try I used a Binding to the Chart to update the Chart and after 2-3 seconds the ui becomes unresponsive and started lagging. I'm currently using an ObservableObject and the .drawingGroup modifier to improve the Performance. This Helps but it's not perfect. Is there a better way to increase the Performance or what's the way to have a realtime drawing line graph? Here's the Code I use: struct ChartView: View { @ObservedObject public var model = FNMeasurementModel() private let gradient = LinearGradient(gradient: Gradient (colors: [.mint.opacity(0.1),.mint.opacity(0.0)]), startPoint: .top, endPoint: .bottom) var body: some View { Chart() { ForEach(model.data) { item in LineMark( x: .value("Ratio", item.ratio ?? .zero), y: .value("Speed", item.speed ?? .zero) ) .interpolationMethod(.catmullRom) .foregroundStyle(.mint) AreaMark( x: .value("Ratio", item.ratio ?? .zero), y: .value("Speed", item.speed ?? .zero) ) .foregroundStyle(gradient) } } .chartXAxis{ AxisMarks(position: .bottom, values: stride(from: 0, to: 1.0, by: 0.2).map { $0 }) } .chartXScale(domain: 0...1.0) .chartYScale(domain: 0...100) .frame(height: 100) .padding(.vertical, 5) } } The ObservableObject class FNMeasurementModel: ObservableObject { @Published public var data: [FNMeasurementResult] = [] func append(_ sample: FNMeasurementResult) -> Void { data.append(sample) } func reset() -> Void { data.removeAll() } } My Result Type public class FNMeasurementResult: Identifiable { public var id: UUID = UUID() public var ratio: Double? public var speed: Double? public init(speed: Double? = nil, ratio: Double? = nil) { self.ratio = ratio self.speed = speed } }
Replies
1
Boosts
0
Views
2.7k
Activity
Apr ’23
Overlapping AreaMarks not working
I am trying to make a chart that looks like: Basically a couple overlapping range AreaMark's, a LineMark and a couple RuleMarks. However when I have two separate AreaMark's I get this: When one or the other of the AreaMark's ForEach loop is commented out it displays the proper graph. Its just the overlap of the two that is wonky. FYI - The top graph was generated by the SwiftUI Charts package on GitHub which we are trying to move away from. Thanks.
Replies
2
Boosts
0
Views
938
Activity
Apr ’23
Using Charts with the storyboard in xcode
Hello, I'm trying to find an easy way to use "Swift Charts" in Storyboard mode with xcode. I understood how it works with swiftUI but can it be done with storyboard only? THANKS
Replies
1
Boosts
0
Views
579
Activity
Apr ’23
How can I apply the modify my Swift Chart based on the ComplicationRenderingMode
For Apple Watch complications displayed on tinted faced, developers can use: @Environment(\.complicationRenderingMode) var renderingMode to see if the watch face is tinted. You can then use the .complicationForeground() modifier to set elements of the complication to match that tint color. (I appreciate that .complicationForeground() is now deprecated in favour of .widgetAccentable() but I believe the behaviour is the same). However, this can only be applied to a view I believe. I'd like to display a Swift Chart where only certain elements of the chart have the .complicationForeground() rather than the whole chart. For example, in one case I'd like the LineMark to pop with the tinted color of the complication whilst the rest of the complication get the gray default tint. Is there a way to do with with the current APIs? Thanks
Replies
2
Boosts
0
Views
1.5k
Activity
Apr ’23
Swift Charts Axis Adjustment
I am working on a Mac app that uses Swift Charts to visualize some data. I can initially plot the data fine. The problem is that I want the ability to "zoom" in on the data. to do this I change the range of the x or y axis using the following modifiers .chartXScale(domain: xMin...xMax) .chartYScale(domain: yMin...yMax) I use a drag gesture to change the values of xMin and xMax for example to zoom in on the data. This does have the effect that I want but the problem is it causes the line to start moving out of the chart area like show below. I don't understand why this is happening. I thought by changing the scale it would cause only the data that is visible on the chart to be displayed.
Replies
1
Boosts
1
Views
1.4k
Activity
Mar ’23
Swift Charts BarMark bar shape when stacked
Hi I'm trying to apply clip shape on a BarMark with stacked values and the result is that it's applying the shape for each stack instead for the whole bar. What I want to achieve: What I got: I noticed that corner radius is applied to the whole bar but just the top of it: Is there any way to get this capsule shape when stacked? My code is: enum Value: Int, Hashable, CaseIterable {     case ftb     case nb     case remaining     var color: Color {         switch self {         case .ftb:             return .tint1         case .nb:             return .tint2         case .ramaining:             return .gray4         }     } } @ViewBuilder var barChart: some View {         Chart {             ForEach(dates, id: \.self) { date in                 let incomeSummary = incomeSummaries.first(where: { $0.date?.inSameDay(as: date) == true })                 ForEach(Value.allCases, id: \.self) { value in                     barMark(for: value, date: date, incomeSummary: incomeSummary)                         .foregroundStyle(value.color)                 } //                .cornerRadius(20, style: .continuous) //                .clipShape(Capsule())             }         }         .chartXAxis {             AxisMarks(values: dates) { date in                 AxisValueLabel(format: .dateTime.weekday(), centered: true)             }         }         .chartYAxis {             AxisMarks { mark in                 AxisValueLabel()             }         }     } private func barMark(for value: Value, date: Date, incomeSummary: IncomeSummary?) -> BarMark {         let amount = amount(for: value, in: incomeSummary)         return BarMark(x: .value("WeekDay", date, unit: .day,                                  calendar: Calendar.localTime),                 y: .value("Income", amount))     } Another issue, I've noticed that when AxisValueLabel is centered the last bar looses its label, is it a bug?
Replies
0
Boosts
3
Views
1.7k
Activity
Mar ’23
Does the new Swift Charts support pie charts?
I now watched all 4 charts WWDC22 videos. It looks like there is no pie chart support. Do I need to build such style by myself or is there a way to implement this in the new Swift Charts framework?
Replies
4
Boosts
1
Views
2.3k
Activity
Mar ’23
SwiftCharts: How to clip data to specific range?
I found that can customise the range of the x and y axes. But my problem is that for line marks some data might just be outside the axes range. If I add .clipped to the chart that would limit it, but then it also clips off some of the axis marks. No Clipping: With Clipping: you see the green line go over the AxisValueLabel area and the topmost label is clipped off. One way I can imagine addressing this without enabling clipping is to create an interpolated value for values that are just outside the chart range so that the line ends exactly at the min/max.
Replies
5
Boosts
2
Views
2.8k
Activity
Mar ’23
Chart: How to achieve a specific X-axis (an awkward log scale)
I'm trying to determine how best to achieve a desired result within Swift Charts. I'm trying to make a sort-of "reversed" log chart. The use case here is for driving into the details of the percentiles from a series latency values stored within a histogram. The X axis percentile values I was hoping to achieve was something along the lines of: 10, 50, 90, 99, 99,9, 99.99, 99.999 With those values being fairly evenly distributed across the chart. If I look at this from an inverted sequence of: ( 1 - (some value) ).reversed() where the values are: 0.00001, 0.0001, 0.0001, 0.001, 0.01, 0.5, 0.1 But I've been struggling with how to start with those values, scale the X axis using a 1-value kind of setup, and then overlaying the values that are more human readable to achieve the end result. Any suggestions on how to tackle this scenario with customizing a chart axis?
Replies
1
Boosts
0
Views
2.1k
Activity
Mar ’23
Launch an animation when a value in picker changes
Hi, I have two charts on the page and you can switch between them with the picker. Can you please tell me how can I make them show with animation? I do not know how to start the animation when I change a chart in the picker. Thank you! struct ChartsView: View {     var stackedBarData: [ToyShape] = [         .init(type: "Cube", count: 0),         .init(type: "Sphere", count: 0),         .init(type: "Pyramid", count: 1),     ]     var charts = ["Bar chart", "Area chart"]     @State private var selectedChart = "Bar chart"     var body: some View {         VStack {             if selectedChart == "Bar chart" {                 Chart {                     ForEach(stackedBarData) { shape in                         BarMark(                             x: .value("Shape Type", shape.type),                             y: .value("Total Count", shape.count)                         )                     }                 }                 .padding(.vertical, 20)             } else if selectedChart == "Area chart" {                 Chart {                     ForEach(stackedBarData) { shape in                         AreaMark(                             x: .value("Shape Type", shape.type),                             y: .value("Total Count", shape.count)                         )                     }                 }                 .padding(.vertical, 20)             }             Picker("Select a chart", selection: $selectedChart) {                 ForEach(charts, id: \.self) {                     Text($0)                 }             }             .pickerStyle(.segmented)         }         .padding(16)     } }
Replies
0
Boosts
0
Views
995
Activity
Feb ’23
Adapt SwiftUI Chart Colour on Cell Selection
How do I best adapt the color of my SwiftUI charts when the cell in a list is selected? The text color seems to be changing automatically to white, but how do I achieve the same for the graph? I'm using primary and secondary color in my graph like this: LineMark(...) .foregroundStyle(.primary) LineMark(...) .foregroundStyle(.secondary)
Replies
0
Boosts
1
Views
893
Activity
Feb ’23
Trading charts tool integration
Hello developers, I'm currently working on an iOS application that requires trading chart functionality, and I'm looking for a solution that I can easily integrate into my app. I've heard about TradingView's charting and technical analysis tools, but I'm not sure if they offer a library that I can use. Can anyone recommend a charting tool that is easy to integrate into an iOS app? Ideally, the tool should offer real-time data streaming, support for multiple chart types, and customizable indicators and drawing tools. Any suggestions or recommendations would be greatly appreciated. Thank you!
Replies
0
Boosts
0
Views
809
Activity
Feb ’23
SwiftUI Charts - MTLTextureDescriptor has width (9649) greater than the maximum allowed size of 8192
Hi, SwiftUI Charts IOS 16.1 I get crash in the Simulator (tried iPhone or iPad). See console message below. The strange thing is that if I ran the same app on my iPhone 12, no crash. Thank you 2023-01-11 13:58:57.306324+1100 MyMoney[52429:14665675] Metal API Validation Enabled 2023-01-11 13:58:57.451214+1100 MyMoney[52429:14665675] [error] RBLayer: unable to create texture: BGRA8Unorm, [19057, 938] 2023-01-11 13:58:57.451426+1100 MyMoney[52429:14665675] [error] RBLayer: unable to create texture: BGRA8Unorm, [19057, 938] 2023-01-11 13:58:57.470351+1100 MyMoney[52429:14665675] -[MTLTextureDescriptorInternal validateWithDevice:], line 1344: error 'Texture Descriptor Validation MTLTextureDescriptor has width (9649) greater than the maximum allowed size of 8192. ' -[MTLTextureDescriptorInternal validateWithDevice:]:1344: failed assertion `Texture Descriptor Validation MTLTextureDescriptor has width (9649) greater than the maximum allowed size of 8192.
Replies
1
Boosts
0
Views
1.7k
Activity
Feb ’23
SwiftUI Charts Issue - Axis Marks
I'm having an issue with SwiftUI charts and was wondering if anyone knows of a solution or has also run into this. I've been trying to plot data for my app and the X axis does not show the dates and the Y axis only has axis marks 0-9. So, I tried to make another file instance to check what's going on. This is what I have import Charts import SwiftUI struct Exercise: Identifiable { let id = UUID() var dateCompleted: Date var reps: Int } struct ContentView: View { private var exerciseMaxRepsArray: [Exercise] = [] init() { // init dummy data for i in 0 ..< 20 { let date = Calendar.current.date(byAdding: .day, value: i, to: .now) ?? .now let rep = Int.random(in: 1...20) exerciseMaxRepsArray.append( Exercise(dateCompleted: date, reps: rep) ) } } var body: some View { GroupBox(label: Text("Daily Max Reps")) { Chart(exerciseMaxRepsArray) { e in LineMark(x: .value("Date", e.dateCompleted, unit: .day), y: .value("Reps", e.reps) ) } .chartYAxisLabel(position: .trailing, alignment: .center) { Text("Reps") } .chartXAxisLabel(position: .bottom, alignment: .center) { Text("Date") } } and this is the result: I've checked and the issue is not the frame. Has anyone else had this issue or have any clue what could be going on here?
Replies
1
Boosts
0
Views
2.2k
Activity
Feb ’23
Swift Charts use custom font for legend
We have a custom font we use through-out our app we've recently starting playing with Swift Charts but can't work out how to use our font in the chart legend easily. Currently we have a simple chart using the default .chartLegend(...). I've managed to use our font in the X-axis and Y-axis by creating our own labels using AxisValueLabel() {} However without making our own completely custom legend, is there a way to specify the font to use in the legend?
Replies
0
Boosts
0
Views
1.2k
Activity
Jan ’23
Charts: How do I position x axis value labels below the associated grid lines
I am working with the new Charts Framework. The axis value labels for the x axis are dates (mm/dd/yy). I have 5 vertical grid lines and am trying to get the dates to be centered below the associated grid line with no success. One additional problem is that the values are in an array that contains 5 dates but only the first 4 get displayed. Any solutions will be appreciated. Below is the code. struct LineChart: View { private var localArray: [TradingDayPrices] init(passedInArray: [TradingDayPrices]) { self.localArray = passedInArray } var body: some View { let minCloseValue: Double = localArray.map { $0.close }.min()! let maxCloseValue: Double = localArray.map { $0.close }.max()! let minDate: Date = localArray[0].timeStamp! let itemCount: Int = localArray.count - 1 let maxDate: Date = localArray[itemCount].timeStamp! Spacer() GroupBox (label: Text("VOO Closing Values For The Past Year") .font(.system(size: 20)) .fontWeight(.bold) .frame(width: 700, height: 50, alignment: .center)) { Chart { ForEach(localArray) { item in LineMark ( x: .value("TimeStamp", item.timeStamp!), y: .value("Close", item.close) ) .foregroundStyle(Color.blue) .lineStyle(StrokeStyle(lineWidth: 1.25)) } // end for each } // end chart .padding(50) .chartBackground { item in Color.white } .chartXAxisLabel(position: .bottom, alignment: .center) { Text("Date") .font(.system(size: 14)) .foregroundColor(Color.black) .frame(width: 50, height: 35, alignment: .bottom) } .chartYAxisLabel(position: .leading, alignment: .center, spacing: 0) { Text("Closing Values") .font(.system(size: 14)) .foregroundColor(Color.black) } .chartXAxis { AxisMarks (values: GetXAxisLabels(min: minDate, max: maxDate)) { value in AxisGridLine(stroke: StrokeStyle(lineWidth: 0.5)) .foregroundStyle(Color.gray) AxisValueLabel() { if let localDate = value.as(Date.self) { let formattedDate = dateToStringFormatter.string(from: localDate) Text(formattedDate) .font(.system(size: 12)) .foregroundColor(Color.black) } } // end axis value label } // end axis marks } // end chart x axis .chartYAxis { AxisMarks (position: .leading, values: GetYAxisLabels(min: minCloseValue, max: maxCloseValue)) { value in AxisGridLine(stroke: StrokeStyle(lineWidth: 0.5)) .foregroundStyle(Color.gray) AxisValueLabel() { if let localValue = value.as(Double.self) { let formattedValue = String(format: "$%.2f", localValue) Text(formattedValue) .font(.system(size: 12)) .foregroundColor(Color.black) } } } // end axis marks } // end chart y axis .chartXScale(domain: minDate...maxDate) .chartYScale(domain: minCloseValue...maxCloseValue) .frame(width: 700, height: 700, alignment: .center) } // end group box } // end of body } // end of structure func GetXAxisLabels(min: Date, max: Date) -> [Date] { var xLabels: [Date] = [] let increment: Int = 90 for i in 0...3 { let value = Calendar.current.date(byAdding: DateComponents(day: (i * increment)), to: min)! xLabels.append(value) } xLabels.append(max) print("\(xLabels)") return xLabels } func GetYAxisLabels(min: Double, max: Double) -> [Double] { var yLabels: [Double] = [] let increment: Double = (max - min) / 4 for i in 0...3 { let value = min + (Double(i) * increment) yLabels.append(value) } yLabels.append(max) return yLabels } let dateToStringFormatter: DateFormatter = { let result = DateFormatter() result.dateFormat = "MM/dd/yy" return result }()
Replies
2
Boosts
1
Views
4k
Activity
Jan ’23