Hi thanks in advance. Is it possible draw line using canvas on xamdatachart?
Hello Sehran,
Thank you for your post.
From the description of your post, I am not entirely sure whether you are looking to simply draw a Line-based series in your XamDataChart, or whether you are looking for the ability to click and drag and be able to draw a line on the XamDataChart's Canvas that way. I believe it is likely that you are looking to do the latter, though. If this is not the case, and you are just looking to draw a LineSeries in your chart, I would recommend that you take a look at our online documentation, here: http://help.infragistics.com/doc/WPF/2015.2/CLR4.0/?page=DataChart_Category_Line_Series.html. If you are looking to draw your own custom lines on the chart, please see the procedure below.
To do this, there are a few events that I would recommend that you handle. They all exist on the XamDataChart and consist of the MouseMove, MouseLeftButtonUp, PreviewMouseLeftButtonDown, WindowRectChanged, and SizeChanged events. The reason that the mouse down related event is a "Preview" event is because after testing this, it doesn't appear that the MouseLeftButtonDown event fires if the user clicks on a marker of a series in the chart.
The idea behind this is to get the root canvas of the XamDataChart or one of the series in it, and keep track of the mouse position relative to that canvas so that you can construct a Line element and show it in the chart. In the PreviewMouseLeftButtonDown event, you can get the position of the point that the user clicked relative to this canvas and set your Line element's X1 and Y1 properties to the Point returned by the e.GetPosition(canvas) method of this event. Then, you can add the Line to this canvas. In the MouseMove event, I would recommend checking to see if the Mouse.LeftButton is pressed and whether the Line element's Tag property is null (this will be explained in a bit). If these two conditions are true, then you can get the mouse position and set the Line's X2 and Y2 properties to this position as well.
The MouseLeftButtonUp, WindowRectChanged, and SizeChanged events are related to the mentioning of the Tag property above. I would recommend using the UnscaleValue methods of your X and Y axes in conjunction with the X1, Y1, X2, and Y2 properties of your Line element. This will allow you to get the actual chart value where the Line should be. I would recommend that you create a custom class to store these objects and then assign that custom object to the Tag property. The reason for this, is because when the chart zooms or the containing window changes, the lines will not be positioned correctly. By using this Tag procedure, you can use the axes ScaleValue method to find the spot where the lines should be placed in the WindowRectChanged and the SizeChanged event of the XamDataChart and rearrange the lines accordingly.
I have attached a sample project that demonstrates the above. I hope this helps you.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
HI- Andrew Goldenbaum
Recently, I use canvas to plot on xamdatachart, also attempt get back x and y axes position, but it seem different function merge with develop frame. the position information not correspond xamdatachart x axes as refer attach figure. In this figure, i mark three red circle in x axes(date point) and canvas line(dotted blue line).Actually, canvas line get x position can not precisely project in xamdatachart's x axes (date point). If any function which like "Ruler" object which auto provide xamdatachart x axes information without use canvas.