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

Logarithmic scale #64

Open
alejoar opened this issue Oct 9, 2014 · 24 comments
Open

Logarithmic scale #64

alejoar opened this issue Oct 9, 2014 · 24 comments

Comments

@alejoar
Copy link

alejoar commented Oct 9, 2014

Is it possible to use log scale? both on vertical and horizontal axis

I still didn't try this but I might use it for my next project, looks really awesome.

@gionkunz
Copy link
Collaborator

Hi @alejoar

This is currently not possible and I'm not sure if and when this will get into Chartist. Let's keep this issue open and track the need for this.

Cheers
Gion

@dscmax
Copy link

dscmax commented Nov 24, 2014

Log scales are used in many applications in engineering. I think this is a very important feature to implement asap.
I'm not a js developer (just starting), but I will give a look to sources and I will evaluate if I will be able to help for this issue.

@alejoar
Copy link
Author

alejoar commented Nov 24, 2014

Indeed, @dscmax. I was actually looking into this to use it in my diploma project to present some results. Right now I'm in another stage, but I presume I'll start working with charts in a couple of months, and I really hope I can use chartist by then, but log scales are a must have for me.

@ilanbiala
Copy link

@gionkunz if the scale is declared as log in the options object, does the animation need to be mathematically scaled like the graph itself?

@gionkunz
Copy link
Collaborator

Once the new axes classes are stable we can create a log scale axis and make it cconfigurable. This is currently WIP and will be stable on dev soon.

@ilanbiala
Copy link

Sounds good.

@sandstrom
Copy link

Sounds awesome, logarithmic scales would be nice.

@gionkunz
Copy link
Collaborator

There is still an open PR that we need to review and unfortunately I didn't find so much time for Chartist lately :( #185

@gionkunz gionkunz mentioned this issue Apr 26, 2015
@gionkunz
Copy link
Collaborator

The groundwork for this is there. It's just a matter of time and contribution to implement an axis. The new dynamic axis instantiating in 0.9.0 makes this very easy. http://gionkunz.github.io/chartist-js/getting-started.html#switching-axis-type

Maybe the FixedScaleAxis and AutoScaleAxis could be extended with an option to plot in log scale?

@hansmaad
Copy link
Contributor

hansmaad commented Sep 4, 2015

I've implemented a scale option for AutoScaleAxis here hansmaad/chartist-js@4ddd949 . Works well for my test cases. Unfortunately, I didn't find any axes unit test, where I could add some quick tests. If it's ok for you I can create a PR.

@jacobq
Copy link
Contributor

jacobq commented Mar 23, 2016

I would very much like to have the ability to ability to automatically apply logarithmic scaling. Is this feature still in dev only? Can I contribute? I'm planning to use chartist in my electron-based desktop application, which requires this feature, and I'd much rather work with the maintainers than fork and make my own hack.
Ultimately, I'm trying to get something similar to what is produced by MS Excel 2016's XY scatter plot:
excel_chart

chartist_chart

@hansmaad
Copy link
Contributor

@jacobq I had a PR for this, but we're still not sure how to integrate this into core chartist. I hope we will get this as core feature or plugin in the next major version.

For now, I'm using this code, to patch chartist in my application:
https://github.com/hansmaad/chartist-js/blob/logAxis/src/scripts/axes/auto-scale-axis.js

I'm using this in production for several month, and it runs fine.

@gionkunz I moved the code to another branch and deleted the PR. Should I reopen?

@jacobq
Copy link
Contributor

jacobq commented Mar 30, 2016

@hansmaad @gionkunz I'm not sure how busy you are / how much time you have to work on chartist, but in case it's helpful, I've attempted to come up with a more general / natural way to integrate scale transformations like this with the rest of the code.

How it basically works is:

  1. Define transformation functions (e.g. Chartist.Transformations.logBase(2))
  2. By default, AutoScaleAxis will use Chartist.Transformations.linear (identity function). The user/caller can override by setting options.scalingTransformation.
  3. In order to keep the nice / uniform spacing, AutoScaleAxis applies the transformation to highLow before calling getBounds then applies the inverse transformation to the results. That way the function being called (getBounds in this case) doesn't need to be concerned with the transformation.

Note: I haven't tried working this into FixedScaleAxis or testing in bar charts yet but plan to do so eventually. Hopefully most of this can be pulled up to Axis cleanly.

If you have time, please take a look and let me know your thoughts. (I know it's a little rough around the edges but perhaps this will give you some ideas or at least generate some discussion.)
https://github.com/jacobq/chartist-js/tree/scale-transformation

@Alessio92
Copy link

@jacobq your script works perfectly, but overrides my ticks.
My situation is a bit different from your. I need to represent logarithmic scale with my ticks ([10, 16, 25...25000]) instead of your (10, 100, 1000).
Any ideas? thank u
Regards,
Alessio
mysituation

@lucadegasperi
Copy link

@jacobq I'm trying to use your implementation but had no success. I want to plot a bar chart and the Y axis needs to be represented with a logarithmic scale. I have no 0 values in my series but what i'm getting is the following error.
Uncaught Error: The input to the logarithm function must be a positive real number not equal to 0. (got 0)

@lucadegasperi
Copy link

@hansmaad is your code to create a log scale still functioning with chartist 0.9.7? I'm having issues understanding how to implement it into my own charts

@hansmaad
Copy link
Contributor

hansmaad commented Jul 14, 2016

@lucadegasperi
Copy link

@hansmaad thanks!

@lucadegasperi
Copy link

@hansmaad I've noticed that what I needed was not a full log scale but a semi-log scale, like the ones used in trading apps. Have you had any luck implementing something similar? thanks.

@hansmaad
Copy link
Contributor

@lucadegasperi According https://en.wikipedia.org/wiki/Semi-log_plot a semi-log plot has only one log axis. You can define one axis with log scale, while the other stays linear. Is this what you mean?

@lucadegasperi
Copy link

@hansmaad my bad, Im fairly new to the subject. What I meant is having a logarithmic scale on one axis (which indeed I have) but not have it tied to the decades. The underlying grid should also be irregular with items less and less spaced apart. Is there a way I can contact you privately?

@metodribic
Copy link

Is there a plan to integrate this in core Chartist in near future?

@gionkunz gionkunz mentioned this issue Feb 17, 2017
@YakovL
Copy link

YakovL commented Feb 22, 2017

Yeah, without both log scale and error bars (#232) out of the box, this is somewhat complicated to use with scientific data..

@hansmaad
Copy link
Contributor

hansmaad commented Jul 1, 2019

I published my log axis patch as npm package:
https://github.com/hansmaad/chartist-logaxis

It also supports minor grid lines now:

image

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