SwiftChart icon indicating copy to clipboard operation
SwiftChart copied to clipboard

Add support for logarithmic scale

Open MarkLyck opened this issue 9 years ago • 5 comments

Can you add support for a log-scale graph? or allowing to choose which Y-values should be shown?

I'm working with data that goes from $25,000 to over $20,000,000,000. Over a 45 year period

And my line is flatlining because of the exponential increase.

To view my line properly I need an logarithmic graph which would show the following values instead:

0 25,000 100,000 1,000,000 10,000,000 100,000,000 1,000,000,000 10,000,000,000 100,000,000,000

Or however many that can fit.

Here's what my data looks like atm.

img_1750

MarkLyck avatar Jun 02 '15 05:06 MarkLyck

Hi, thanks for the good idea. This month I could work on it. Let see if I get some free time. (or if you don't mind to send a pull request... 😀)

gpbl avatar Jun 02 '15 09:06 gpbl

That would be amazing!

I've been looking at your code since a few hours before creating the issue. But I can't figure out where or how to implement a log-scale y-axis.

If I do figure it out, I will most definitely be sure to make a pull request. But so far I've got nothing.

This is an absolute requirement for my project, and there are no libraries out there, not even for Obj-c that uses a logarithmic scale. So unfotunately there's no reference.

MarkLyck avatar Jun 02 '15 09:06 MarkLyck

Did this ever get implemented? I'm still searching for a useable Chart system that has support for a logarithmic scale.

MarkLyck avatar Jul 27 '15 08:07 MarkLyck

Sorry @MarkLyck I couldn't find time for this. Couldn't you just pass down the logarithmic values to the series?

gpbl avatar Jul 31 '15 20:07 gpbl

Some code I put together today that might help others with this case:

extension Array where Element == Double {
   func logify() -> Array { return self.map { log2(pow(abs($0), $0.signum())) } }
}

extension FloatingPoint {    
   func signum( ) -> Self {
      if self < 0 { return -1 }
      if self > 0 { return 1 }
      return 0
   }	
}

Sources: 1, 2

wallowabk avatar May 17 '19 00:05 wallowabk