infinum / flutter-charts

Customizable charts library for flutter.
https://pub.dev/packages/charts_painter
MIT License
144 stars 42 forks source link

TargetLineDecoration out of chart #51

Closed cc13com closed 2 years ago

cc13com commented 2 years ago

Hello,

I'm using your widget to visualize stock data in my app. The line chart is showing the values from the past and I added a "TargetLineDecoration" to show the stop value.

It happens that the stock values over the time are much lower than the stop value. In this case the "TargetLineDecoration" is out of the chart (on top), somewhere on the screen. Please see the picture with the "TargetLineDecoration" in red.

Chart
charts.Chart(
                      height: 300,
                      state: charts.ChartState.line(
                        charts.ChartData.fromList(
                          result
                              .map((e) => charts.BubbleValue<void>(e))
                              .toList(),
                        ),
                        itemOptions: const charts.BubbleItemOptions(
                          padding: EdgeInsets.symmetric(horizontal: 2.0),
                          maxBarWidth: 4.0,
                        ),
                        foregroundDecorations: [
                          charts.TargetLineDecoration(
                              target: _stopKurs, targetLineColor: Colors.red),
                          charts.SparkLineDecoration(lineColor: Colors.black)
                        ],
                        backgroundDecorations: [
                          charts.GridDecoration(
                            showVerticalGrid: false,
                            verticalAxisStep: 1,
                            horizontalAxisStep: 1,
                            showHorizontalValues: false,
                            textStyle: const TextStyle(
                              fontSize: 24,
                            ),
                            gridColor: Theme.of(context).dividerColor,
                          )
                        ],
                      ),
                    ),

How can I avoid that? My wish/requirement is to move the line chart with the stock values down (there is a lot of fee space under the line chart) that the "TargetLineDecoration" will fit in the chart.

Best, CC13

lukaknezic commented 2 years ago

Hey @cc13com. So this looks to me like something that lib should handle by itself. So i'm going to fix that.

But for now if you need some quick fix best solution is to provide axisMax to ChartData. that will make sure that axisMax is the max value of the chart. So you put current stop value as axisMax in case actual data goes over axisMax the chart will choose the new max value.

cc13com commented 2 years ago

Hey @lukaknezic,

with axisMax it looks better. Thanks for this.