Open iamiota opened 1 year ago
Hi @iamiota
Thanks for detailed report. I was able to reproduce it with your code easily and fixing it right now. There is a issue when calculating size for widgets when axisMin is set. I will add some tests to cover this case as well so we can be sure that values are displayed correctly 😄
@lukaknezic Hi Luka, thank you for your fix.❤️ I have tried the latest code, and the size of the widget is now correct.
However, I have encountered another issue when dynamically modifying the chart data.
If _mappedValues
, axisMin
and axisMax
are the props of LineChart
, and when the props change according to the following, the chart throws repeat errors: 'BoxConstraints has a negative minimum height.'
Additionally, in the video, it can be observed that the animation of the line extends beyond the horizontal axis area.
I used ClipRect
to clip the AnimatedChart
to prevent the line animation from being drawn across the full screen.
final List<List<ChartItem<double>>> _mappedValues = [
[ChartItem(2.0), ChartItem(5.0), ChartItem(8.0), ChartItem(3.0), ChartItem(6.0)]
];
axisMin: 2
axisMax: 8
/// AnimatedChart's duration: const Duration(milliseconds: 500),
/// If milliseconds = 30, everything is good.
/// data change to
final List<List<ChartItem<double>>> _mappedValues = [
[ChartItem(32.0), ChartItem(35.0), ChartItem(38.0), ChartItem(33.0), ChartItem(36.0)]
];
axisMin: 32
axisMax: 38
https://github.com/infinum/flutter-charts/assets/7531576/a7c2443b-10f8-463d-a24d-001de75049cf
negative minimum height should also be fixed, in same branch 😄
First of all, thank you for this amazing library, I really like the idea of using widgets to create charts.
I'm creating a line chart with
target line
(y: 3.6) andtarget area
(y: 0 ~ 2). I encountered some issues after settingaxisMin
andaxisMax
:1. I have a
TargetAreaDecoration
from 0 to 2, whenaxisMin
is set to 2, it is incorrectly displayed on the x-axis.The solution I came up with is to dynamically modify the
targetMin
andtargetMax
of theTargetAreaDecoration
based onaxisMin
andaxisMax
. For example, whenaxisMin
is 1, I would change theTargetAreaDecoration's targetMin
from 0 to 1, so it won't be displayed on the x-axis anymore.2. From the blue area in the graph, it can be observed that the rendering behavior of
widgetItemBuilder
is inconsistent with that ofSparkLineDecoration
. The size ofwidgetItemBuilder
is much larger thanSparkLineDecoration
.I created a
Position
Widget withinwidgetItemBuilder
and positioned the point widget using itstop
property. If theverticalMultiplier
parameter can be added towidgetItemBuilder
, I can calculate the correct position of the point:3. The target line is also being displayed in the wrong place.
The solution I came up with is similar to the first issue. I dynamically modify
verticalMultiplier * (3.6 - axisMin)
based onaxisMin
andaxisMax
.Do you have any suggestions? Thank you.
Codes