fl_chart icon indicating copy to clipboard operation
fl_chart copied to clipboard

Are there any plans to implement logarithmic axis?

Open pangxb opened this issue 4 years ago • 17 comments

ATT. Log Plot

pangxb avatar Sep 03 '20 06:09 pangxb

Plotting a chart based on a function is not implemented yet.

imaNNeo avatar Sep 05 '20 17:09 imaNNeo

I know this request is old but I would be interested in a logarithmic axis too. This is not plotting a chart based on a function, this is being able to use non linear axis values.

https://en.wikipedia.org/wiki/Logarithmic_scale

mlprod35 avatar May 30 '21 18:05 mlprod35

I'm in the same boat with @pangxb and @mlprod35 , having a logarithmic axis is very beneficial.

Some data points do not look good when plotted on linear scale.

Please see the images below for comparison. For reference and more elaboration, check out this link. Here is the comparison:

  • In the first picture you can see Linear Scale (what's currently only supported by fl_chart) linear_scale

  • In the second picture you can see Logarithmic Scale (what we want, the to-be-supported feature mentioned in this issue) logarithmic_scale

om-ha avatar Dec 21 '21 14:12 om-ha

To our surprise, out of all graphing/charting/plotting libraries in flutter. Almost no one supports Logarithmic scale. I think this would make fl_chart stand out.

Only mentions regarding logarithmic scale in other charting libraries can be found here:

om-ha avatar Dec 21 '21 14:12 om-ha

Hello guys. I understood the feature. Stay tuned for the update!

imaNNeo avatar Jan 28 '22 13:01 imaNNeo

We're excited for this @imaNNeoFighT , this is a deal-breaker and a great feature to see implemented!

om-ha avatar Feb 06 '22 07:02 om-ha

Hey @imaNNeoFighT. Any update on the issue?

NachiketaVadera avatar Apr 04 '22 13:04 NachiketaVadera

Still no news, guys. Can you paste some samples from other libraries that allow you to create logarithmic charts?

imaNNeo avatar Apr 14 '22 16:04 imaNNeo

Here you go:

  • https://github.com/mzimmerm/flutter_charts
  • https://github.com/mzimmerm/flutter_charts/search?q=logarithmic

Just as amazing as fl_chart, there is this flutter_charts that implemented logarithmic scale as well.

om-ha avatar Apr 17 '22 11:04 om-ha

This is a great library. Its just missing a log feature.

I figured out a workaround for a small feature set:

Draw data log

spots: List.generate(
        data.length,
        (index) {
          return FlSpot(
            double.parse(index.toString()),
            data[index].price== null
                ? 0
                : log(data[index].price?? 0) / ln10,
          );
        },
      ),

Fix tooltip value to correct one

getTooltipItems: (touchedSpots) {
    var value = pow(10, e.y).toDouble();
}

Sesa1988 avatar Jun 11 '22 20:06 Sesa1988

so ,Automatically match the Y-axis ,set : spots: List.generate( data.length, (index) { return FlSpot( double.parse(index.toString()), data[index].price== null ? 0 : log(data[index].price?? 0) / ln10, ); }, ),

or:getTooltipItems: (touchedSpots) { var value = pow(10, e.y).toDouble(); }

? but But when I use it, it doesn't seem to work

helloworkcupid avatar Apr 12 '23 07:04 helloworkcupid

where is the code for the picture?

helloworkcupid avatar Apr 12 '23 11:04 helloworkcupid

Fix tooltip value to correct one

can you share your code ? thank you

helloworkcupid avatar Apr 13 '23 00:04 helloworkcupid

Currently using the following workaround:

import 'dart:math';

// Convert all spots

FlSpot(
  m.timestamp,
  log(m.value <= 0 ? 1 : m.value) / ln10
)
LineChartData(

  // Correct tooltip
  lineTouchData: LineTouchData(
	enabled: true,
	touchTooltipData: LineTouchTooltipData(
	  getTooltipItems: (List<LineBarSpot> touchedBarSpots) {
		return [
		  LineTooltipItem(
			pow(10, touchedBarSpots[0].y).toString(),
			const TextStyle(color: Colors.black),
		  ),
		],
		textAlign: TextAlign.start,
	  ),
	),
  ),

  // Correct max
  maxY: (log(max) / ln10 + 1),

  // Correct grid
  gridData: FlGridData(
    show: true,
    drawVerticalLine: false,
    horizontalInterval: (log(max) / ln10 + 1) / 5,
  ),
),

denxorz avatar Nov 16 '23 15:11 denxorz

Any update on the issue?

LinschotenMelle avatar Mar 04 '24 13:03 LinschotenMelle