Open herna opened 3 weeks ago
Well, I ended up calculating my own interval as per my needs, automatic interval calculation doesn't take in mind label length and elements overlap.
Another issue is minIncluded and maxIncluded elements doesn't work properly by default so min/second values and max/penultimate values usually overlap:
This might also happen in the other axis with simpler and shorter labels:
The problem is the second value calculated by function Utils.getBestInitialIntervalValue()
is inserted not matter what, it doesn't take care of the space available in the chart:
/// Finds the best initial interval value
///
/// If there is a zero point in the axis, we want to have a value that passes through it.
/// For example if we have -3 to +3, with interval 2. if we start from -3, we get something like this: -3, -1, +1, +3
/// But the most important point is zero in most cases. with this logic we get this: -2, 0, 2
double getBestInitialIntervalValue(
double min,
double max,
double interval, {
double baseline = 0.0,
}) {
final diff = baseline - min;
final mod = diff % interval;
if ((max - min).abs() <= mod) {
return min;
}
if (mod == 0) {
return min;
}
return min + mod;
}
Facing thesame issue.
Describe the bug Automatic axis interval is not properly calculated. In the example below I am trying to represent the evolution of a particular value over time.
To Reproduce
Screenshots Incorrect behaviour:
https://github.com/user-attachments/assets/1f26e141-2230-47f7-9c1f-9b6ae612f9b8
Correct behaviour after own modifications:
https://github.com/user-attachments/assets/c10c17b0-897b-4d3e-8d78-cd1aa53a6abc
Versions
As you can see, dates in the x-axis overlap, I am just using example "LineChartSample1" in the repo with slight modifications.
Find below the modifications I had to make in order to work as per my needs, just in case you find it useful. Don't take these modifications for granted, this is just intended to prove my point.
In the code below, the value that works is
accurateInterval
, the originalroundInterval(accurateInterval);
gives completely wrong number of elements that can fit in the axis (much larger than actual value).Also notice the
pixelPerInterval
parameter, you should be able to indicate this some way depending on the length of final titles in the axis. Or it should be automatically calculated based on font size and labels on the axis.From this:
To this:
Again I cannot fully understand all calculations so this works as long as
minIncluded
andmaxIncluded
are bothtrue
. This modification is needed to avoid the overlapping of the titles, specifically for first and last elements.Function
Utils().getBestInitialIntervalValue()
doesn't work for this particular case, it always says elements don't overlap but they do all the time.From this:
To this: