-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[BUG] Floating point linear scale for text values #3723
Comments
I can see how this is an issue, but I'm not sure it's right to automatically switch the axis type. cc @chartjs/maintainers thoughts? |
If nothing ploted with 'good' data then it should be considered a bug. |
This problem is a direct consequence of chartjs not having notion of data types. For example Google Charts distinguishes this data types |
This is definitely a feature request. I was thinking about this a bit more and realized that there are also a lot of other things that need to be worked out at the same time. For instance, it's pretty common (judging by the number of times people have asked questions about it or opened issues) to pass in data that looks like Lets use this issue to brainstorm a proposal and then we can figure out what features need to get done to get there. |
I should add that some of these changes might require a major version bump if we can't maintain backwards compatibility |
Creating an ordinal scale shouldn't be too difficult. I think it could derive from the category scale and simply override |
There is three steps in the process of visualizing chars:
Apart from visualization chartjs absolutely ignores preparation leaving this task for developers and has limited support for formating... I think everyone should share their vision on how this parts should fit together.
Most of the time preparation is done on the server side thats why it actualy looks OK to ignore this step on client side, but there are cases where you don't have access to server-side and forced to do preparation on client side. Or because of known problems with dates in javascript, you want to prepare date as string and parse it using Moment.js on client-side. Thats why i think preparation should be part of the BUNDLE but not necesarily be part of chartjs library. I think providing a standart set of formating options for tooltips and scales is a MUST and should be in the core (number formating, date formating). All custom formating should be done through common interface, not only user-defined function but some kind of pluggable 'formatter' classes/functions. |
@etimberg changing |
I like the Google Charts approach where preparation and formatting is done before visualization and stored as pair of |
http://numeraljs.com/ is the library we looking for!? |
NumeralJS looks interesting and could solve a lot of the parsing and formatting problems. In terms of storing both the raw and formatted values, are you thinking something like:
I'm guessing the user would supply the data and we would build the One thing to think about with that example is that the formatting needs to also apply to the tick marks. Presumably if the axis is using '$' we want the tooltip to show the same thing. In terms of implementing this, I'm wondering if we can ship it as a plugin. As you noted, not everyone wants to download a huge library and we've already got complaints about the current size being too large. What I was envisioning the plugin would do would be
|
Storing formatted values is not a panacea, but looks good and easy to implement. One of the issues you mentioned is that it will only work for 'category' scales... What is interesting in NumeralJS is that they have this idea of format/unformat, so you can transform in each way... If you think about it, all this 'number as string' issues happening because data come preformated and you want it to be 'unformated' to raw values wich can be used by chartjs library and then you want it to be formated again. So format/unformat feature is interesting. Also it's already have alot of formats and allow easy integration of custom formatters. |
Interesting question about formating in a situation where same dataset having multiple scales. Is it possible? Any usecases? |
For tooltip, formatting will be something like this:
For scale use array of user-defined ticks or autogenerated ticks and follow the same steps to get formatted value. It's expected behaviour to use same formatting for scale and tooltip, but it shouldn't be a hard restiction... So if scale does not have any formatting it can use formatting from dataset... Looks ok to me... Also this requires option to disable formatting or opposite... |
The case of the same dataset having multiple scales shouldn't happen and isn't supported.
That's a very good way to think about it. Something like numeral (doesn't have to be this) will definitely solve problems.
That sounds like a good idea to me. It would maintain backwards compatibility for anyone using custom functions already. |
❤️ |
Current Behavior
Y scales show floating point linear scale from -1.0 to 1.0 and does not plot anything
Expected Behavior
When values are of type string, scales should be of type category and use values as ticks
Possible Solution
For values of type string change scales type to category and use distinct values as ticks
Steps to Reproduce (for bugs)
http://codepen.io/anon/pen/GNeZaJ
Environment
The text was updated successfully, but these errors were encountered: