我无法在SwiftUi中显示图表轴的轴标签。图表显示,但轴和图例的标签不显示。我的代码显示图表如下。the result of the code are stated below
struct ReferData:Identifiable,Hashable {
let id = UUID()
let month:String
let referCount:Int
init(month:String,referCount:Int) {
self.month = month
self.referCount = referCount
}
}
import Charts
struct ReferDashBoardView: View {
@State var referData:[ReferData] = [
ReferData(month: "Jan", referCount: 10),
ReferData(month: "Feb", referCount: 23),
ReferData(month: "Mar", referCount: 18),
ReferData(month: "Apr", referCount: 48),
ReferData(month: "May", referCount: 12),
ReferData(month: "June", referCount: 38),
ReferData(month: "July", referCount: 23),
ReferData(month: "Aug", referCount: 29),
ReferData(month: "Sept", referCount: 34),
ReferData(month: "Oct", referCount: 42),
ReferData(month: "Nov", referCount: 32),
ReferData(month: "dec", referCount: 45)
]
var body: some View {
ScrollView(.vertical,showsIndicators: false) {
VStack(alignment:.leading,spacing: 12){
Chart{
ForEach(referData,id: \.self) { item in
BarMark(
x: .value("Month", item.month),
y: .value("ReferCount", item.referCount)
)
}
}
.foregroundColor(.orange)
}
.frame(maxWidth: .infinity)
.frame(minHeight: 350)
}
.padding()
}
}
2条答案
按热度按时间cwxwcias1#
为了显示轴标签,您需要使用Chart{}下面的.chartXAxisLabel()。像这样:
rekjcdws2#
为了显示轴标签,您需要使用Chart{}下面的.chartXAxis()和.chartYAxis()。例如:x1c 0d1x