Charts icon indicating copy to clipboard operation
Charts copied to clipboard

LineChartRenderer's drawCubicBezier exaggerates the curve between two points when drawing a long line

Open ryanjohndias opened this issue 6 years ago • 3 comments

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:

screen shot 2018-05-24 at 15 39 53

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

ryanjohndias avatar May 21 '18 14:05 ryanjohndias

have you tried horizontal bezier mode?

liuxuan30 avatar Jun 22 '18 00:06 liuxuan30

Yeah I'm also facing the same issue

YogeshV12 avatar Oct 25 '21 13:10 YogeshV12

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.

aliyailina avatar Oct 09 '23 11:10 aliyailina