WPF Toolkit Chart: Positions of Data Point Visualization shifted when changing data values

风流意气都作罢 提交于 2019-12-10 02:56:37

问题


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 data has changed to different values:

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?

来源:https://stackoverflow.com/questions/9924047/wpf-toolkit-chart-positions-of-data-point-visualization-shifted-when-changing-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!