Post not yet marked as solved
I'm wondering if Apple will add a weekDay type ScaleType for plotting stock market charts.
The Date scaleType assumes that the weekend days (Saturday/Sunday) should be within the plotted data. But the typical stock market chart omits the weekends and holidays (non-market days) from the charts. Would Apple be interested in providing this new Chart Scaling Type. Or is there a way to extend the Charts Framework to allow this type of chart?
For Example: the X Axis might look like:
M T W T F M T W T F T W T F
Post not yet marked as solved
Hi,
I use a barmark/linemark SwiftUI chart in my app and when i want to change the fontsize and color of the AxisValueLabel for the x-axis then it does not seem to work properly.
When i set the following:
AxisValueLabel()
.foregroundStyle(.red)
or
AxisValueLabel()
.font(.system(size: 30))
it doesn't show up.
Kind regards,
Tom
Post not yet marked as solved
Is there a way to create scrolling/paging behavior in the charts just like is done in the Health app? I have a similar app that also displays health data (such as heart rate and steps) and with my current custom charts the user can page back to see data from previous weeks (by default it shows the current week). Just like in the health app the user can go back as long as there is data, which can be several years (so hundreds go pages). I'd love to replace my custom implementation with Swift Charts but for that I do need this scrolling behavior.
anyone figured out how to customise the Y axis values? id like to be able to process the. axis values and. then display them in the. format id like. eg. "1000" I'd like to display as "1k"
the furthest Ive been able to get is to get the axis to display a static text as the number ie "Y" in the code below. but I haven't been able to access the value. in the code below 'value' seems to be an AxisValue which stores the value but I can't seem to access it in a format I can process.
.chartYAxis {
AxisMarks() { value in
AxisGridLine()
AxisTick()
AxisValueLabel {
Text("Y")
}
}
}
id like to be able to do something like this:
.chartYAxis {
AxisMarks() { value in
AxisGridLine()
AxisTick()
AxisValueLabel {
if value > 1000000000000.0 {
Text("\(value / 1000000000000.0)t")
} else if value > 1000000000.0 {
Text("\(value / 1000000000.0)b")
} else if value > 1000000.0 {
Text("\(value / 1000000.0)m")
} else if value > 1000.0 {
Text("\(value / 1000.0)k")
}
}
}
}
Post not yet marked as solved
Is there a way to have a point mark only come out as a very small circle? I want PointMarks that are basically just 1 point large black dots.
Post not yet marked as solved
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.
I want to draw a chart where I have two line marks (one for each child each) and behind it area marks for percentiles. If I don't add any foregroundStyle then the line marks get connected.
struct GrowthChart: View
{
@ChartContentBuilder
func oneSlice(row: PercentileRow, slice: Slice) -> some ChartContent
{
AreaMark(
x: .value("Day", row.month),
yStart: .value("Max", row.dictionary[slice.startKey]!),
yEnd: .value("Min", row.dictionary[slice.endKey]!)
)
.foregroundStyle(by: .value("Percentile", slice.number))
}
let percentileColors: [Color] = [
.blue.opacity(0.1),
.blue.opacity(0.2),
.blue.opacity(0.3),
.blue.opacity(0.4),
.blue.opacity(0.5),
.blue.opacity(0.4),
.blue.opacity(0.3),
.blue.opacity(0.2),
.blue.opacity(0.1)
]
var body: some View
{
VStack {
Chart {
ForEach(percentiles.rows) { row in
ForEach(slices) { slice in
oneSlice(row: row, slice: slice)
}
}
ForEach(children) { child in
ForEach(child.data) { dataPoint in
LineMark(
x: .value("Month", dataPoint.month),
y: .value("Height", dataPoint.height)
)
.foregroundStyle(by: .value("Name", child.name))
}
}
}
.chartForegroundStyleScale(
range: Gradient (colors: percentileColors)
)
.aspectRatio(contentMode: .fit)
.padding()
Spacer()
}.padding()
}
}
I don't understand how to group the individual marks. Apparently you have to add a foregroundStyle to each with a .by specifying a category. I found this chartForegroundStyleScale in an example on the internet, but I can only get it to show this gradient. But how do I specify different colors for the LineMarks?
Post not yet marked as solved
Would love to use Swift Charts framework. But I still need to support older iOS versions. Do I need create custom chart solution for iOS15 or any chance SwiftCharts will be backward compatible?
Post not yet marked as solved
Hi!
I want to use the new SwiftUI Charts (iOS 16) in my app and it seems that the orientation does not work. I want to make the AxisLabels vertical oder verticalReversed or give it a certain angle but all three methods don't seem to work.
AxisMarks() { _ in
AxisValueLabel(orientation: .angle(Angle.degrees(45.0)))
}
}
Am i doing something wrong or is it a bug in the beta framework?
Kind regards,
Tom
Post not yet marked as solved
How does one create a custom mark for Swift Charts? I'm trying to add a live indicator to a stock app line mark. Is a custom mark the best way to do this?