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

xValues on X-Axis for non-continuous dates #2398

Closed
kettch opened this issue Apr 27, 2017 · 5 comments
Closed

xValues on X-Axis for non-continuous dates #2398

kettch opened this issue Apr 27, 2017 · 5 comments

Comments

@kettch
Copy link

kettch commented Apr 27, 2017

I've been trying to migrate to Charts 3.0, but I'm running into trouble with a candle stick chart. I'm rendering candle sticks that match days of the week (with sometimes some days even missing), as any financial chart for a stock is usually rendered. With the previous version of Charts, here's what I was doing:

  • Starting at index 0, creating values with the index by iterating over days I needed to render in the chart
  • Providing a set of xValues that gave the formatted date

That way, I could have a chart with one candle per x index, with correct dates displayed as I wanted them. All is good...

Unfortunately, now with Charts 3.0, those xValues have disappeared, and I can only give a double value, using a formatter to display the date as I want it. I found a few issues here on this topic, but unfortunately, all of them assume that you either have continuous data or that you want to interpolate or leave blanks in between, which is not the case here.
So, to sum it up:

  • if I encode the date as a time interval since the first date, I'll have dates displayed properly on the axis, but the values will be positioned according the X values, with blanks in between
  • if I use straight index as I was doing before, I'll have a continuous graph as I want it, but then formatting to display the right dates will be impossible as I don't have any info on what the date for that index is anymore

Taking the candle stick sample as an example, the first screen would be what I would get with time intervals as X values, while the second one will be using straight and continuous indices (imagining there are dates to be displayed, too):
screen shot 2017-04-27 at 19 00 27
screen shot 2017-04-27 at 19 01 05

Is there a way I'm missing that would allow for proper dates and an X-axis without blanks, or is that something that is just not possible and should be considered a bug?

@liuxuan30
Copy link
Member

liuxuan30 commented Apr 28, 2017

I'll have a continuous graph as I want it, but then formatting to display the right dates will be impossible as I don't have any info on what the date for that index is anymore

If this is the case, you can just creating a mapping that maps [0,1,2,...,n] as xVals to your date strings and no blanks, e.g. 0 for Jan 1, 1 for Jan 3, 2 for Feb 28, etc. Am I missing anything?

@kettch
Copy link
Author

kettch commented Apr 28, 2017

I had thought of that, but that would mean that suddenly, the configuration of the axis, that is probably better as being independent from the data itself, would suddenly become tied to it.
Of course, it's the case to some extent now, as you have to configure your axis differently depending on whether you want to display numbers or something else, but at least you didn't have to change that configuration each and every time you fed new data to the graph, which is a clear separation of responsibility.

Now to make this work, this would mean that I would have to put a formatter that would need to know about the data, and be updated each and every time the data changes, which seems prone to problems, and blurs the line between the data and the chart configuration.

So yes, it should work, but it means reworking my code quite a bit because data and configuration were quite clearly separated (which I will do to try and make it work for now), as they were on the Charts side (configuration was once and for all, data was dynamic and changing), and it doesn't feel like a formatter should know that "10" means "03/04/16".

Wouldn't you agree that may reveal that something is just missing on the side of Charts (even though you can hack around it)?
It could just be passing back xValues with the data (maybe at some other point), or having a special type of axis that skips X values that don't have data. Others like Shinobi Charts handle this by having a special type of X axis where you can tell it what X values you want to skip, as an example (that's even a special one for dates where you know you want to skip some days regularly, and can add others, even though that's still limited).
It looks to me like this is a pretty standard case (financial charts amongst others), that shouldn't be left to a mere hack...

@liuxuan30
Copy link
Member

On one side, the library is not perfect and lots of things to improve, and need your help, if you are able to pull a request for the standard cases you mentioned.

But the axis is always tied to data I think, because it needs to know the range and what label you want to display, and needs to calculate the width/height to make sure it looks good.

To your question, I don't have you project, but having an array that's holding all of the date strings, does not mean a formatter should know that "10" means "03/04/16"? it just pass 10 and you get what you want to display, don't quite understand why you seem against this.

Basically, the new x axis behaves like y axis now, so it's very different now. We think make x axis behaves like y axis gives more flexibility.

@vrutberg
Copy link

vrutberg commented Feb 15, 2018

Has there been any developments on the concerns raised by this issue? I'm also implementing financial charts and ran into the exact same issue as described by @kettch. (ping @liuxuan30)

@liuxuan30
Copy link
Member

liuxuan30 commented Feb 16, 2018

no, you have to figure out a way that suits you.
x axis is not flexible, so either you use index x values like 1,2,3 or the real x value, it depends on your requirement.
the 2.x chart x axis is treated as index based, which is not quite ideal, so it behaves like y axis now.

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

No branches or pull requests

3 participants