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?
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
what i want access to is the information displayed in the tooltip. i have no way to get that information from the callback
Hi Willroy,
Currently, we are validating your query and will update the complete details in one business day.
Regards,
Sriram Kiran
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