This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, I am drawing a foreground element on the chart. However, when I zoom in I am not sure how to calculate its new position from the XZoom, YZoom parameters in the zoom event. The foreground element subscribes to the chart zoomed event and the handler for it gets called. I have the prezoom x and y coordinates of the foreground element. Thanks, Peter |
|
|
Hello Peter I think the easiest way to do this is to store the logical X and Y axis values of where the element should appear on the chart, and then re-calculate the physical position of the element whenever the chart is zoomed or panned or changes size. You can calculate the pixel position by calculating the ratio between the logical and pixel size of the X and Y axis, then use this ratio to convert the know logical positions of the element into their new pixel positions. In the code below you can see I have encapsulated this logic into a class that extends Canvas. You can create an instance of this class and add it to the Chart.ForegroundElements collection. This element will take care of subscribing to the events it needs to listen to.
You can try out this element in your own chart to see how it behaves and then modify it to suit your application. Let me know if you have any questions about it. -Jason |
|
|
Hi Jason, Thanks it seems to be working. I have one more question. I allow the user to right click on the chart and add this new custom foreground element which is nothing more than just a small square (10X10). When the user right clicks I record the x value of the point where the right click occurred. Now I need to draw the foreground element at this x coordinate but the y coordinate should be on the plot line. How do I find the y coordinate for the line which corresponds to the recorded x coordinate? From the series? Thanks, Peter |
|
|
Hello Peter All lined based series have a GetY method where you can pass in the logical x value and it will return the logical y plot value that intersects with the plot line. If the type of the series reference you have is the base type DataSeries rather than something like LineSeries, then you can cast the DataSeries into a LineAreaSeriesBase to get access to this method. This is already a feature in our charting framework, no need to wait for a nightly build. By the way, if you are going to allow the user to add multiple elements using right click, you may want to modify the code I gave you so that a single PositionedForegroundElement can manage all added elements, rather than adding a new PositionedForegroundElement every time. This will reduce the UIElement count. -Jason |
|