Charts
Charts copied to clipboard
LineChartRenderer's drawCubicBezier exaggerates the curve between two points when drawing a long line
- [x] I've read, understood, and done my best to follow the *CONTRIBUTING guidelines.
What did you do?
When using a data set where there are relatively large gaps on the x axis (for example, in time-based charts), in combination with LineChartDataSet.mode = .cubicBezier
, the line has exaggerated curves
Example code
override func viewDidLoad() {
super.viewDidLoad()
chartView.dragEnabled = true
chartView.leftAxis.enabled = false
chartView.rightAxis.enabled = false
let values = [
ChartDataEntry(x: 0, y: 10),
ChartDataEntry(x: 1, y: 11),
ChartDataEntry(x: 2, y: 12),
ChartDataEntry(x: 3, y: 13),
ChartDataEntry(x: 4, y: 20),
ChartDataEntry(x: 30, y: 37), // Notice the gap in the x values
ChartDataEntry(x: 31, y: 38),
ChartDataEntry(x: 32, y: 40),
ChartDataEntry(x: 33, y: 39)
]
let set1 = LineChartDataSet(values: values, label: "")
set1.drawIconsEnabled = false
set1.setColor(.black)
set1.setCircleColor(.red)
set1.lineWidth = 3
set1.circleRadius = 6
set1.drawCircleHoleEnabled = false
set1.mode = .cubicBezier
chartView.data = LineChartData(dataSet: set1)
chartView.setVisibleXRangeMaximum(10)
}
What did you expect to happen?
The line should not curve backwards
What happened instead?
The line has exaggerated curves (e.g. negative/backwards) as follows:
Charts Environment
Charts version/Branch/Commit Number: 3.1.1 Release Xcode version: 9.3 Swift version: 4.1 Platform(s) running Charts: iOS macOS version running Xcode: 10.13.4
have you tried horizontal bezier mode?
Yeah I'm also facing the same issue
Facing absolutely the same issue. @liuxuan30 with horizontal bezier there is no such issue.
P.S. I using older version of library and cannot right now check with the latest one.