-
-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linechart not plotting correctly with large number of points #64
Comments
mmm interesting,
struct LineChartDemoView: View {
let data: LineChartData = weekOfData()
var body: some View {
LineChart(chartData: data)
.id(data.id)
.frame(minWidth: 150, maxWidth: 900, minHeight: 150, idealHeight: 500, maxHeight: 600, alignment: .center)
.padding(.horizontal)
.navigationTitle("Week of Data")
}
static func weekOfData() -> LineChartData {
func makeDataSet() -> [LineChartDataPoint] {
let datapoints: [LineChartDataPoint] = (1...600).map { index in
if index < 240 {
return LineChartDataPoint(value: Double.random(in: 50...80))
} else if index > 241 && index < 250 {
return LineChartDataPoint(value: Double.random(in: 90...100))
} else if index > 251 && index < 290 {
return LineChartDataPoint(value: Double.random(in: 100...160))
} else if index > 291 && index < 300 {
return LineChartDataPoint(value: Double.random(in: 160...180))
} else if index > 301 && index < 350 {
return LineChartDataPoint(value: Double.random(in: 90...100))
} else {
return LineChartDataPoint(value: Double.random(in: 60...80))
}
}
return datapoints
}
let data = LineDataSet(dataPoints:
makeDataSet(),
legendTitle: "Steps",
pointStyle: PointStyle(),
style: LineStyle(lineColour: ColourStyle(colour: .red), lineType: .curvedLine, strokeStyle: Stroke(lineWidth: 1)))
let chartStyle = LineChartStyle()
return LineChartData(dataSets : data,
metadata : ChartMetadata(title: "Step Count", subtitle: "Over a Week"),
chartStyle : chartStyle)
}
} Gives me: Which looks right to me. And with 2400 data points: |
🤔 @willdale I am running v 2.5.0 on iPhone 11 (iOS 14.5) I tried making sure your code was the same as mine but still seeing the different charts. Can't figure out what might be different between yours and mine?
|
If its helpful here is the data I am plotting:
|
This library currently only plots evenly spaced, this would mean if there is an area where there is more data, it will get spread out. Could that explain it? |
@willdale yes that must be it then, heart rate data from the Apple watch is sampled sporadically (e.g. more frequent during a workout, less frequent during other times of day). 🤔 |
Is there a date component in It would be good if the library could handle more time/date based rendering but I'm not sure when I'll get time to look at it. |
@willdale I tried interpolating a HR at every second of the day but that gives me over 56,000 values to chart so far today which I think might be too many as its crashing but I can't tell why. |
A couple of Ideas: To take inspiration from a Garmin app I use; to show a whole day they average to every two minutes - giving a maximum 720 data points for a day , then for workouts there is a separate chart that shows every second. To take inspiration from Apple; to show a whole day they use a ranged bar chart showing the highest and lowest values in an hour. See |
@willdale thanks for taking the time! I will give both a shot and see what works best. Thanks again for a great library. 🍻 |
I'm working on v2.6 which overhauls all the axes labels. Hopefully this will solve a myriad of problems! @kennedycraig, Is that using |
Hi, Will. No, its using .chartData(). Note that the xlabels bug only appears with a rotation modifier. Without the rotation modifier, I works as expected.
|
Thanks, I'll work on a fix for an up and coming update. |
Hopefully v2.6 has fixed this. 🙏 If not feel free to reopen this. |
For some reason 2.6 is not pulling in Xcode via swift package manager. No matter whether I reset the package cache and/or force update to latest version. Any ideas? |
Just deleted the dependency and re-added - still get 2.5 |
@kennedycraig fixed in v2.6.1. Odd issue with git not tracking |
@willdale revisiting this, have you given any thought to adding support for time/date plotting as is discussed above? In other words correctly plotting a chart of heart rates even though the samples non equal gaps in between (resting HR every 5 minutes vs. workout HR every second). |
@gesabo if you want to stick in a pull request, I'm more than happy to review it. |
@willdale I would love to if I had those chops 🤣 but I'm not even sure where to start. |
Is there some number of data points that are too much for a line chart? I'm loading 609 heart rates here, the first chart is using iOS charts and the 2nd is using SwiftUI Charts. It looks like the spike in the middle (a workout) should be tighter together). Anything I can do to fix this? 🤔
![IMG_57212197C1E8-1](https://user-images.githubusercontent.com/9816100/116941998-bb953600-ac3e-11eb-9258-95afa4c158ea.jpeg)
![IMG_95BBF270A45B-1](https://user-images.githubusercontent.com/9816100/116942000-be902680-ac3e-11eb-97f3-463fe725bddc.jpeg)
The text was updated successfully, but these errors were encountered: