ChartsOrg / ChartsOrg/Charts

Example of creating linear regression/trend line on LineChartView

Open
#4,041 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Can anyone provide example code to create a linear regression/trend line for a LineChartView?

Here's example data I'm using to create the LineChartView:
```
dataEntries.append(ChartDataEntry(x: 0 y: 700))
dataEntries.append(ChartDataEntry(x: 1, y: 770))
dataEntries.append(ChartDataEntry(x: 2 y: 810))
dataEntries.append(ChartDataEntry(x: 3, y: 850))
dataEntries.append(ChartDataEntry(x: 4, y: 900))
dataEntries.append(ChartDataEntry(x: 5 y: 800))
dataEntries.append(ChartDataEntry(x: 6, y: 750))
dataEntries.append(ChartDataEntry(x: 7, y: 1100))

let chartDataSet = LineChartDataSet(values: dataEntries, label: nil)
let chartData = LineChartData(dataSet: chartDataSet)
self.chartView.data = chartData
```

So what I need to do is create a second data set that's a trend line showing the progress. Any help is appreciated.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.