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

X Axis for Candle Sticks from Realm #1214

Closed
kettch opened this issue Jul 3, 2016 · 7 comments
Closed

X Axis for Candle Sticks from Realm #1214

kettch opened this issue Jul 3, 2016 · 7 comments
Labels

Comments

@kettch
Copy link

kettch commented Jul 3, 2016

Hey,

I've been trying to set up a candle stick chart from Realm results, and ran into quite a few surprises:

  • At first, I was trying to use dates as the xIndexField, as it feels pretty normal to use dates for a candle chart, but it wouldn't work, as at some point, it will try to convert it to an Int
  • So, I tried using an integer value, computed on the fly as a readonly property on my Realm objects, but it wouldn't work either, as it has to be a persisted property to be sorted when creating the data set
  • Then, I tried disabling the sorting (and do it before with the actual persisted date), but then it was crashing later because it was trying to access the property through Realm
  • Fine, so I tried making it a persisted property, still as an integer, but then it would complain that it has to be a String (in RealmChartUtils.toXVals)
  • Obviously, I can't use a string containing a formatted date (like "2016/11/25"), as it can't be converted to an integer either...
  • Last, I tried a string containing a numerical value, but obviously it can't be converted to an Int (in RealmCandleDataSet.buildEntryFromResultObject)

After looking at the sample code, the only way to create such a chart from Realm results is to:

  • create a persisted property for each single data point, with an integer index
  • create another persisted property for each single data point, with a formatted string
    Wouldn't it make sense to allow the use of non-persisted properties to do that? It is extremely cumbersome to have to create persisted properties for that, and terrible performance-wise when you're juggling with a database containing millions of those datapoints, and these properties can be inferred from one that already exists.

Alternatively, I'm wondering if it wouldn't be better to just provide a RLMResults, already ordered, and just use the index of those objects from the RLMResults as the index on the X Axis. This would probably just solve it all in one go, and allow for anything to be used as long as Realm can sort it.

@liuxuan30
Copy link
Member

it seems a long story.. but right now the x axis is index based one, so the date you are saying is merely a string at a specific index.
The authors are working on a float x axis, but it's a huge work.

@kettch
Copy link
Author

kettch commented Jul 4, 2016

Well, I saw that issue when looking here, but what you're expecting is for the dates to be used as a value, with space in between depending on the date intervals.
That's not exactly what I'm describing here, as I don't care about how much time there is between each date. I'm perfectly fine with the interval being fixed between two values when rendered, and just having the order of dates inducing an index for rendering.

My main issues here (apart from finding out how to make this work, but that's just me...) are that the types that can be provided for the X Axis are extremely constrained, while there could be some ways to get those that are way more straightforward, and that this creates an issue of having to persist those values, which feels a bit overkill.

@liuxuan30 liuxuan30 added the idea label Jul 4, 2016
@danielgindi
Copy link
Collaborator

Can you please try again with Charts 3.0? As the x-index concept has gone away, you should be able to set dates as x values for each entry. (You will still have to convert them to doubles)

@danielgindi
Copy link
Collaborator

I've checked with Charts 3.0, and it seems that the Realm CandleStick sample works fine, no crashes or anything.

All you need to do for having dates as the X value, is represent them as Doubles, which is the standard practice. in iOS the NSTimeInterval is a typedef for Double...
And then add a formatter to format as dates.
There's a (non-realm) demo that does exactly that.

@nicholassmith
Copy link

When's 3.0 due for release? I'm using Charts for a date based graph but if it's a while off I'll work around the xIndex Int for the moment.

@danielgindi
Copy link
Collaborator

It will be a few days, that we dedicate for feedback, bugfixes etc.
But it seems to be more stable than the latest release, so if you're not releasing your app yet for a few days, I'd go with 3.0.

@nicholassmith
Copy link

Awesome, it's a few weeks off so I'll keep my workaround in place and update to 3.0 when it's baked. Thanks for the quick reply!

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

No branches or pull requests

4 participants