9

I use a WPF Toolkit chart to display several line series with data points. I have created styles for the LineDataPoints that use a canvas on which symbols (like a circle) are drawn.

Here's one of the style definitions:

<Style x:Key="CircleDataPointStyleRed"
       TargetType="chartingToolkit:LineDataPoint">
    <Setter Property="Background"
            Value="Red" />
    <Setter Property="IsTabStop"
            Value="False" />
    <Setter Property="Width"
            Value="10" />
    <Setter Property="Height"
            Value="10" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="chartingToolkit:LineDataPoint">
                <Canvas>
                    <Ellipse Height="10"
                             Width="10"
                             Stroke="Red" />
                </Canvas>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

When I load data into the view model, the chart is displayed correctly, the lines are visible and the data points drawn centered to the correct position so the center point of the circle lies where the actual data point is. Now when I load a different set of data into the chart (change the ObservableCollections the LineSeries are bound to), the lines are still drawn correctly but the circles are not drawn centered any more but with the upper left corner of their canvas lying on the location of the actual data point. When I resize the chart, the positions of the circles gets correct again.

Here's some screen shots to clarify:

After first data is loaded: After first data is loaded

After data has changed to different values: After data has changed to different values

After the chart has been resized: After the chart has been resized

What I have tried so far (each to no avail):

  • Set HorizontalAlignment and VerticalAlignment on the Canvases in the Templates
  • Tried to call UpdateLayout() as well as all the InvalidateXxx methods on the control

How can I achieve the data points to be drawn at the correct positions even after changing the data?

seveland
  • 181
  • 12
Mathias Weyel
  • 809
  • 6
  • 18
  • I'm not going to log an answer with this guess unless it works, but I think you need to look at Measure and MeasureOverride (I think that's what they're called), or find a way to hook into OnResize. – Rob Perkins Nov 06 '12 at 02:36
  • I tried to recreate your issue using [this](https://github.com/JohanLarsson/WpfToolkitChart) did not see it. – Johan Larsson Jan 21 '13 at 22:18
  • @Momo Yes, I did actually. But frankly, I don't remember half of it. What I remember, is that the misplaced objects are not redrawn correctly due to some size being 0. The solution incorporated subclassing one of the classes in the framework and adjusting these sizes. Unfortunately I can't look it up, because I have moved to a new project and we ditched the wpf toolkit in favor for a homebrew solution as it could not be made to take quick updates to the points too well. – Mathias Weyel Feb 19 '14 at 08:43
  • @MathiasWeyel Okay, well thanks for the tip! – MoMo Feb 19 '14 at 19:18

0 Answers0