ChartsOrg / ChartsOrg/Charts

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

Open
#3,465 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

* [x] I've read, understood, and done my best to follow the [*CONTRIBUTING guidelines](https://github.com/jjatie/Charts/blob/master/CONTRIBUTING.md).

## 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](https://user-images.githubusercontent.com/6240969/40489129-b95f6976-5f68-11e8-9982-ca83376b7fd0.png)

## 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**

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the example data and `.cubicBezier` mode, then trace `LineChartRenderer`'s `drawCubicBezier` implementation. Verify the fix against the long x-axis gap and confirm that the rendered line no longer curves backwards.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.