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")
}
}
}
}
I found that instead of parsing the encapsulated
AxisValue
you can transform it into the orginal value.For an
Int
I am doing it so:.chartXAxis() { AxisMarks(values: .stride(by: 1)) { let month = $0.as(Int.self)! } }
The
.stride(by: 1)
overrides the automatic selection of marks.just tried. using .stride works. have to calculate your own values but probably a better solution than parsing debug descriptions. would be nice if we could vary stride values for different ranges eg. below 0 and above 0 but I suppose that's a different problem.