Skip to content
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

Live feed #21

Closed
AllenConquest opened this issue Aug 2, 2015 · 8 comments
Closed

Live feed #21

AllenConquest opened this issue Aug 2, 2015 · 8 comments

Comments

@AllenConquest
Copy link

Is there a way to create a LineChart that can be updated, say every 5 seconds, with a new datapoints, and will smoothly scroll to the left as the data is added?

@ivnsch
Copy link
Owner

ivnsch commented Aug 2, 2015

SwiftCharts currently doesn't support this. The nearest live-updates functionality achievable is redisplaying the chart with new data (or adding points on the fly, but this will not update the axes).

Letting this open since this is planned long term, but I can't say when it will be done. PRs are also welcome!

@acrux27
Copy link

acrux27 commented Sep 9, 2015

On the topic of redisplaying the chart with new data - what is the best way to reload certain elements, and/or the whole chart?
Also, similarly, is there a way to freeze the axes magnitudes?

I am a relatively unskilled (in terms of app development) uni student trying to incorporate the library into an app for engineering design, and I would love the ability to show multiple sets of data (read: lines) on the graph as the user manipulates a single variable (which will change the input array).

Ultimately, I was thinking the best way would be to redisplay the axes, chart area and all elements apart from the chart line itself, which would remain drawn for comparison with the next series of values. Thus a user could compare one value for the variable with a new one on the chart. As it is now, when you change the variable, the chart axes will change in magnitude given that it is linked to the input array with some level of offset as far as I understand.

Thank you in advance for bearing with me - new to all this!

@ivnsch
Copy link
Owner

ivnsch commented Sep 9, 2015

Not sure if I fully understand the problem but wouldn't something similar to the multiaxes example solve your problem (see video 1:32). In case all the datasets share the same value range or you can create a range that comprises the different possibilities, a multiline chart would suffice.

@acrux27
Copy link

acrux27 commented Sep 9, 2015

I am trying to display one set of data - for example with linear points from (0,0) to (0.5, 300). I then want to keep that set of data on the graph, and display a new set of datapoints. The second set of datapoints is being changed by a slider - arbitrarily let us say that the slider simply multiplies the x and y coordinates by a scalar.

If the slider was at 1 for points from (0,0) to (0.5, 300) and I slide it to 2, I would have a line with twice the gradient running from (0,0) to (1, 600). By knowing the max value of the slider, I can find the maximum possible x and y values, so I was hoping to freeze the axes at these values so I could change the slider and all that is drawn is the datapoints line (not a new set of axes etc).

A multiline chart would work however the sets of data are dependent on the slider moving so are unknown when the graph (and hence axes) is first rendered.

In the process I want to be able to clear previous lines drawn such that there are only two lines shown on axes that are static (unsure on how to do this). I.e. I want to show one set of datapoints, the user then changes the slider and gets a second line on the same axes to compare the two, and then if they do it a third time, the first dataset is wiped and the second and third remain.

I am just unsure how to clear previous lines (or any element of the chart for that matter) and to freeze the axes magnitude.

Thanks for your help!

@ivnsch
Copy link
Owner

ivnsch commented Sep 10, 2015

You can store the axis values and whatever model data has to be fixed (e.g. in instance variables). Each time that you want to update the chart simply re-create it, with your current model data. You implement the logic to decide which lines to show, etc. at model level i.e. have an array with the lines you want to show as instance variable, on slider change event, update this array, then call the method to reinitialise the chart with the current model data.

I would probably create a private struct to hold all the "static" parts, like the axes models, etc. store it in an instance variable and use it to re-create the chart each time. And separately (or in the struct itself, depending on preference) store the variable models, which you likewise use to create the chart.

This assumes that the changes in the slider are discrete, if it's continuous it's likely that it will cause stuttering in the UI, since the chart would reinitialise everything on each little slider update. It may be fluent though if you store directly the layers (specially axes layers) in the struct / instance variable, as the initialisation of this is what consumes most resources and you would be doing it only the first time. I have not tested this scenario though and can't guarantee that it works correctly. May need some small adjustments, please try it out and depending on your results we look further.

It should also be not difficult to modify the chart to manage mutable models. If above doesn't lead to satisfactory results we also can do this.

@acrux27
Copy link

acrux27 commented Sep 14, 2015

Okay fantastic thank you - I had not considered using a private struct to maintain the static axes but that is making a lot sense.

In terms of the slider, it is discrete in terms of its upper and lower values being definied. As such the axes can be set on the basis of the maximum X and Y possible given the array and the slider value.

And finally, excuse my ignorance (as I said, new to this and learning as I go along) - what is the method to reinitialise the chart? I have an issue where every time I am re-creating the chart it is drawing over the previous chart resulting in an ugly mess of lines.

@ivnsch
Copy link
Owner

ivnsch commented Sep 14, 2015

You have to call clearView() on the chart, this will remove its view from the superview, then just initialise normally like in the examples. If you're using autolayout you need something similar to this

@ivnsch
Copy link
Owner

ivnsch commented Oct 6, 2015

Closing for now since there are no plans to add this in the foreseeable future. If there's a change I'll come back to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants