fl_chart
fl_chart copied to clipboard
Are there any plans to implement logarithmic axis?
ATT.
Plotting a chart based on a function is not implemented yet.
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.
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
) -
In the second picture you can see Logarithmic Scale (what we want, the to-be-supported feature mentioned in this issue)
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:
-
flutter_charts
- Issue: How to display Y axis values in logarithmic scale?
-
ex51AnimalsBySeasonManualLogarithmicScale
-
ExamplesEnum.ex51AnimalsBySeasonManualLogarithmicScale
- Looks like logarithmic scale charts are currently worked on. Only con about this library is that it's not as customizable as the others. I could be wrong here.
-
charts
- Issue: Support logarithmic scales
- There is
LinearScale
, but noLogarithmicScale
yet. - This is a charting library by Google.
-
fcharts
- LogScale. Not sure if this library supports LogarithmicScale charts.
- An outdated library that is very limited.
Hello guys. I understood the feature. Stay tuned for the update!
We're excited for this @imaNNeoFighT , this is a deal-breaker and a great feature to see implemented!
Hey @imaNNeoFighT. Any update on the issue?
Still no news, guys. Can you paste some samples from other libraries that allow you to create logarithmic charts?
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.
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();
}
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
where is the code for the picture?
Fix tooltip value to correct one
can you share your code ? thank you
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,
),
),
Any update on the issue?