I would like to overlay completed trades on the SfCartesianChart using a candle series by drawing a line between the entry price and close price. I have looked into trendlines and markers but cannot see how I would draw a simple trade line between 2 points on the chart.
Any suggestions?
Many Thanks
Alistair
Hi Alistair,
Greetings from Syncfusion.
We have achieved your requirement ‘drawing a line between the
open price and close price’ with the help of the onCreateRenderer
callback in the chart to create a customizable
series. This allows you to create a custom rendering in series.
We have prepared a sample based on your requirement and attached a sample below
for your reference.
Screenshot:
For more details, please refer this ug:
https://help.syncfusion.com/flutter/cartesian-charts/callbacks#oncreaterenderer
Note: We have rendered the black line to connect the open and close value. Please change the sample based on your requirement.
Regards,
Lavanya A.
Hi Lavanya,
Thanks for getting back to me. I think you may have mis-understood the requirement though - I would like to draw a line from the open and close of a trade, not the open and close of a candle. I need to just plot the 2 points on the same chart as the candle series and join them with a line. Ideally I would be able to pop up a tooltip at the start point and end point to show the trade details.
I have updated your demo screenshot to illustrate.
I think the onCreateRenderer looks like it will support this - maybe it is should be LineSeries on top of the CandleSeries? Is that possible?
Many Thanks
Alistair
Hi Arconomy,
We are checking for a feasible solution to achieve your requirement and we need time on this. We will update the further status in one business day on 30 January 2023. We appreciate your patience until then.
Regards,
Yuvaraj.
Hi Yuvaraj,
Thanks for looking into this. Let me know if I can provide any support.
Many thanks
Alistair
Hi Arconomy,
We are still looking for a feasible solution to achieve your requirement and we need one more business day. We will update the further detail on 31 January 2023. We appreciate your patience until then.
Regards,
Yuvaraj.
Thanks for the update Yuvaraj.
Looking forward to hearing from you tomorrow.
Many thanks
Alistair
Hi Arconomy,
We have achieved your requirement with the help of a custom painter widget. We have placed the chart widget inside a Stack, and used the SchedulerBinding to generate a list of CustomPaint widgets. Each CustomPaint object has a LinePainter object as its painter. We have stored the line trade points in the tradePoints property, and the LinePainter takes start and end offsets as inputs, which are calculated by converting the trade point data into pixel values using the pointToPixel method in the ChartSeriesController, accessed from the onRendererCreated callback. We have shared a sample below for your reference.
Screenshot:
Note:
We have used simple data points for rendering the line above the candle. Please change the tradePoints values based on your requirement.
Regards,
Yuvaraj.
Hi Yuvaraj,
Well done! Thanks for spending time on this. I will try and integrate your solution today and let you know how I get on.
Many Thanks
Alistair
Hi Yuvaraj,
I have integrated your solution into my chart and made some updates to suport redrawing the trade lines when the chart pans and zooms. I still have a few issues that I am struggling with though;
1) Preventing the CustomPaint widgets being repainted and added to the Stack if they are outside the visible chart area (see screenshots). Is there a way of getting the minimum and maximum visble points on the X axis and Y axis?
2) Do you know whether I could apply the TooltipBehavior to the CustomPaint Widget to show the trade details (e.g. Datetime, entry and close prices)?
Many Thanks
Alistair