3

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.

enter image description here

Legend
  • 113,822
  • 119
  • 272
  • 400

3 Answers3

2

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.

Emond
  • 50,210
  • 11
  • 84
  • 115
  • Agree with Erno. Using `VisualTreeHelper` dig into the charting control's visual children to extract its `Canvas` panel that has the graph blotted on to it. Then using container generator get the nodes that you want to group under a rectangle and after that using node's absolute coordinates w.r.t. the canvas panel, draw a rectangle that encompasses the nodes you want. – WPF-it Oct 19 '11 at 10:53
1

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)

  • Oh no. I have a scatter plot on which I want to mark a set of points that are close to one another. To do this, I was thinking of using the coordinates of the points and creating a rectangle that I can then overlay over the chart. The only way I know of doing this currently is to create these points as another series and add them to the chart itself. I added a figure to clarify this further. – Legend Oct 19 '11 at 09:29
1

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.

dowhilefor
  • 10,971
  • 3
  • 28
  • 45