-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
Adding a trend line to Line Charts and Bar Charts? #104
Comments
@gesabo I have considered it, but decided to leave the average calculation as an implementation detail. Here is an easy way to add a line on top of a This goes high up the View Modifier chain. .extraLine(chartData: data, legendTitle: "Test") {
extraLineData
} style: {
extraLineStyle
} Then this further down. .extraYAxisLabels(chartData: data, colourIndicator: .style(size: 12)) Data and styling. private var extraLineData: [ExtraLineDataPoint] {
[ExtraLineDataPoint(value: 200),
ExtraLineDataPoint(value: 90),
ExtraLineDataPoint(value: 700),
ExtraLineDataPoint(value: 175),
ExtraLineDataPoint(value: 60),
ExtraLineDataPoint(value: 100),
ExtraLineDataPoint(value: 600)]
}
private var extraLineStyle: ExtraLineStyle {
ExtraLineStyle(lineColour: ColourStyle(colour: .blue),
lineType: .curvedLine,
lineSpacing: .bar,
yAxisTitle: "Bob",
yAxisNumberOfLabels: 7,
animationType: .raise,
baseline: .zero)
} |
@willdale thanks so much! Had no idea |
Where in the view chain is it? BarChart(...)
.extraLine(...) |
|
@willdale oh I see you meant all the way to the top! Got it! Fixed now 👍 |
No worries. |
@willdale would it be possible to add .extraLine to a RangedLineChart as well? |
It should already work, are you facing an issue? |
@willdale yes unless I'm doing something wrong, I'm getting
|
Hi, Change Should solve it. |
@willdale got it, yes it does. 👍 Is there any way to display the points on the extraLine? |
This has been added in v2.9.0. Theres also a optional change to the API to make is slightly neater. .extraLine(chartData: data,
legendTitle: "Test",
datapoints: extraLineData,
style: extraLineStyle) |
@willdale is there a way I can force the ExtraLine Point Marker to alway show or always be at the top z position? in my code here below... the middle value's (5.5) point parker does not show because it is covered by the green range. If I set the RangeLineStyle's FillColour to .clear then the 5.5 point shows. 🤔
|
should be fixed in v2.9.1 |
@willdale it is, thanks! 🍻 |
@willdale have you considered adding a trend line or moving average line? I've done this in the past in the iOS Charts lib manually by adding another line with data points that average some number of total points on the chart. For example if I had 100 data points on line 1, line 2 would be constructed using 10 data points (0-10 average = point 1, 11-21 = point 2 etc.).
If you were to incorporate this in the library then maybe add a number to pass in for granularity, i.e. adding a trend line like my example above would pass in maybe the number 10, as in every 10 data points and more granularity might be 5, so that the trend line represented the average of every 5 data points. I think this would be a nice feature to add if not too difficult to incorporate, both for line charts but bar charts and ranged bar charts as well.
Thanks for considering!
The text was updated successfully, but these errors were encountered: