简体   繁体   中英

Is it possible to draw a rectangle over a charting element?

I have some XAML like this drawing a scatterplot of a time series (X-Axis: DateTime, Y-Axis: Integer Value):

<Grid Name="chartgrid">
    <charting:Chart Name="scatterplot">
    </charting:Chart>
</Grid>

I am able to add a graphic object such as a line to this grid as one of its children but have to do so using X and Y coordinates that are different from the ones used by the chart control. Of course this is expected because the chart sets up its own axis.

The only approach I could think of is to add some dummy points to the graph as a different series but am hoping there is a better way to do this. Any suggestions?

EDIT: Added a figure to clarify further.

在此输入图像描述

The only way I can think of is by examining the Virtual Tree looking for both axis objects.

Perhaps by using the VisualTreeHelper

Once you know their positions and their sizes combined with the scale information you can hopefully get from the chart control you could calculate the transformation from chart point to Silverlight coordinate.

Are you tying to adorn the Grid with a rectangle? If so why not using a border? ... (Sorry I dont have option to comment yet. Hence I asked you this question as an answer)

I would create an Adorner to do the actual drawing of your overlay stuff. Create this layer in your Chart control, or a class that encapsualtes both. And give the Chart class the proper Matrix or Transform to convert the given coordinates in your overlay objects to the current Chart transform. Also helpful is TransformToDescendant which allows you to convert a point from your chart for example, to your adorner.

I don't know what and how you transform the position on your chart IScrollInfo, RenderTransform etc. But with this information i think you can achieve what you are looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM