We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Get Trendline value

Is there a way to get the trendline point data information ( value at the point where the vertical trackball or crosshair vuts the trendline)? or atleast a way to know the value where the forcasts of the trendline ends?


4 Replies

NR Natrayan Ramalingam Syncfusion Team November 9, 2022 06:40 AM

You can get the trendline point information with the help of the onRenderDetailsUpdate callback, and it contains information about the trendline such as slope, calculated data points, and intercept. Enable the tooltip in the trendline to see the control point's value. Please refer to the following code snippet.


Code snippet:

SfCartesianChart(

        primaryXAxis: NumericAxis(),

        tooltipBehavior: TooltipBehavior(enable: true),

        series: <CartesianSeries<ChartData, double>> [

          SplineSeries<ChartData, double> (

            dataSource: chartData,

            name: 'SplineSeries',

            xValueMapper: (ChartData data, _) => data.x,

            yValueMapper: (ChartData data, _) => data.y,

            trendlines: <Trendline> [

              Trendline (

                enableTooltip: true,

                onRenderDetailsUpdate: (TrendlineRenderParams args) {

                  print(args.calculatedDataPoints);

                },

                type: TrendlineType.linear,

                name: 'Trendline',

                color: Colors.blue,

              )

            ],

          ),

        ],

      ),


Screenshot:


You can refer to the below attached sample along with user guide documentation for more details about onRenderDetailsUpdate callback and trend line.

https://help.syncfusion.com/flutter/cartesian-charts/callbacks#onrenderdetailsupdate-trendline

https://help.syncfusion.com/flutter/cartesian-charts/trendline




Attachment: f178718_1ba40ca4.zip


WI Willroy November 13, 2022 12:14 AM

what i want access to is the information displayed in the tooltip. i have no way to get that information from the callback



SK Sriram Kiran Senthilkumar Syncfusion Team November 15, 2022 09:30 AM

Hi Willroy,


Currently, we are validating your query and will update the complete details in one business day.


Regards,

Sriram Kiran



NR Natrayan Ramalingam Syncfusion Team November 16, 2022 12:05 PM

Your requirement can be achieved by converting the onRenderDetailsUpdate callback trendline pixel values to chart point with the help of pixelToPoint, and chartSeriesController callbacks. Also stored the calculated trendline chart points in the trendLineData field. Please refer the following code snippet.


Code snippet:

onRenderDetailsUpdate: (TrendlineRenderParams args) {

      args.calculatedDataPoints!.forEach((element) {

              CartesianChartPoint<dynamic> chartPoint = _chartSeriesController!.pixelToPoint(element);

                    trendLineData.add(ChartData(chartPoint.x, chartPoint.y));

      });

},

onRendererCreated: (ChartSeriesController controller) {

      _chartSeriesController = controller;

},


You can refer the below attached sample along with user guide documentation for more details about onRenderDetailsUpdate, onRenderedCreated callback and pixel to point public method.

https://help.syncfusion.com/flutter/cartesian-charts/callbacks#onrenderdetailsupdate-trendline

https://help.syncfusion.com/flutter/cartesian-charts/callbacks#onrenderercreated

https://help.syncfusion.com/flutter/cartesian-charts/methods#pixeltopoint




Attachment: f178718_c1c978c5.zip

Loader.
Live Chat Icon For mobile
Up arrow icon