Open ns1045 opened 2 years ago
I was not able to replicate your result. Maybe attach the rest of your code? I made a simplified version of your implementation and got a correct result. You might be able to spot something that is causing your issue. ` struct Chart: View {
let data = lineData()
var body: some View {
LineChart(chartData: data)
.pointMarkers(chartData: data)
.xAxisGrid(chartData: data)
.yAxisGrid(chartData: data)
.yAxisLabels(chartData: data)
.id(data.id)
.padding()
}
static func lineData() -> LineChartData {
let data = LineDataSet(dataPoints: [LineChartDataPoint(value: 458.0),
LineChartDataPoint(value: 464.3),
LineChartDataPoint(value: 480.3),
LineChartDataPoint(value: 490.8),
LineChartDataPoint(value: 500.2),
LineChartDataPoint(value: 490.7),
LineChartDataPoint(value: 460.0)],
pointStyle: PointStyle(pointSize: 2))
let chartStyle = LineChartStyle(xAxisGridStyle: GridStyle(numberOfLines: 7),
yAxisGridStyle: GridStyle(numberOfLines: 8),
yAxisNumberOfLabels: 8,
baseline: .minimumWithMaximum(of: 450),
topLine: .maximum(of: 520))
return LineChartData(dataSets: data,
chartStyle: chartStyle)
}
}
struct ContentView_Previews: PreviewProvider { static var previews: some View { Chart() } } `
`struct Chart: View {
let data = lineData() let height: Double;
init(_ height: CGFloat) { self.height = height; }
var body: some View { FilledLineChart(chartData: data) .pointMarkers(chartData: data) .infoBox(chartData: data) .yAxisLabels(chartData: data) .xAxisLabels(chartData: data) .id(data.id) .padding() .frame(height: height) }
static func lineData() -> LineChartData {
let data = LineDataSet(dataPoints: [LineChartDataPoint(value: 0), //458.0),
LineChartDataPoint(value: 0), //464.3),
LineChartDataPoint(value: 0), //480.3),
LineChartDataPoint(value: 0), //490.8),
LineChartDataPoint(value: 0), //500.2),
LineChartDataPoint(value: 0), //512.8),
LineChartDataPoint(value: 0), //490.7),
LineChartDataPoint(value: 0)], //460.0)],
legendTitle: "",
pointStyle: PointStyle(pointSize: 1, borderColour: UI_Constants.background, fillColour: .white, pointType: .filled),
style: LineStyle(lineColour: ColourStyle(colours: [.white, UI_Constants.lightBackground], startPoint: .top, endPoint: .bottom), lineType: .line))
let chartStyle = LineChartStyle(infoBoxPlacement: .infoBox(isStatic: true),
infoBoxBorderColour: UI_Constants.background,
infoBoxBorderStyle: StrokeStyle(lineWidth: 1),
markerType: .vertical(attachment: .line(dot: .style(DotStyle()))),
xAxisGridStyle: GridStyle(numberOfLines: 20,
lineColour: UI_Constants.background.opacity(0.2),
lineWidth: 1,
dash: [2],
dashPhase: 1),
xAxisLabelPosition: .bottom,
xAxisLabelColour: UI_Constants.background,
xAxisLabelsFrom: .chartData(rotation: .degrees(90)),
yAxisGridStyle: GridStyle(numberOfLines: 5,
lineColour: UI_Constants.background.opacity(0.2),
lineWidth: 1,
dash: [16],
dashPhase: 1),
yAxisLabelPosition: .leading,
yAxisLabelColour: UI_Constants.background,
yAxisNumberOfLabels: 5,
baseline: .minimumWithMaximum(of: -20), //450),
topLine: .maximum(of: 20), //520))
globalAnimation: .easeOut(duration: 1));
return LineChartData(dataSets: data,
chartStyle: chartStyle)
}
}
struct Chart_Previews: PreviewProvider { static var previews: some View { Chart(100) } }`
I can reproduce that with following example code. The effect does not occurs when I remove the .infoBox(chartData: data)
I have the same issue when adding .infoBox, is there a fix for this issue?
In a line diagram the marked points do not match the corresponding values. The y-Axis is shifted by ca 6