如何更改Oxyplot轨迹值的字符串格式?

5
如果我更改轴的字符串格式,它会对轴起作用(请参见图片中的黑色圆圈)。但是我如何更改轨迹值的字符串格式(红色圆圈)?

enter image description here


请参见 https://oxyplot.userecho.com/en/communities/1/topics/583-trackerformatstring-question。 - Ian Botham
2个回答

5

根据Ramin给我的提示,我希望自己回答这个问题。

我稍微研究了一下源代码,发现有一个TrackerFormatString可以更改:

<oxy:LineSeries TrackerFormatString="{}{0}&#x0a;{1}: {2:0.0}&#x0a;{3}: {4:0.0}"/>

请注意我的代码中的&#x0a;,这是在XAML中输入换行符的方式。
还请注意在开头的{},这是XAML中的转义字符。
如果在C#中,只需:
{0}\n{1}: {2:0.0}\n{3}: {4:0.0}

这也很好。 - rmojab63
更多关于此编程问题的讨论请参见http://discussion.oxyplot.org/forums/1-general/topics/583-trackerformatstring-question/。 - Felix
1
当前讨论链接为-https://oxyplot.userecho.com/en/communities/1/topics/583-trackerformatstring-question - Ian Botham

3

您需要设置DefaultTrackerTemplate。这里是一个小例子,以显示设置方式:

<Grid>
    <oxy:Plot Title="AAA">
        <oxy:Plot.Axes>
            <oxy:LinearAxis Position="Left" Title="Left: " />
            <oxy:LinearAxis Position="Bottom"  Title="Bottom: " />
        </oxy:Plot.Axes>
        <oxy:Plot.Series>
            <oxy:LineSeries x:Name="ls" ItemsSource="{Binding Points}"/>
        </oxy:Plot.Series>
        <oxy:Plot.DefaultTrackerTemplate>
            <ControlTemplate>
                <oxy:TrackerControl Position="{Binding Position}"  
                                BorderThickness="1">
                    <oxy:TrackerControl.Content>
                        <StackPanel >
                            <DockPanel>
                                <TextBlock Text="{Binding XAxis.Title}" Foreground="Red" />
                                <TextBlock DockPanel.Dock="Right" Text="{Binding DataPoint.X}" Foreground="Red" />
                            </DockPanel>
                            <DockPanel>
                                <TextBlock Text="{Binding YAxis.Title}" Foreground="Green" />
                                <TextBlock DockPanel.Dock="Right" Text="{Binding DataPoint.Y}" Foreground="Green" 
                                       FontWeight="Bold" />
                            </DockPanel>
                        </StackPanel>
                    </oxy:TrackerControl.Content>
                </oxy:TrackerControl>
            </ControlTemplate>
        </oxy:Plot.DefaultTrackerTemplate>
    </oxy:Plot>
</Grid>

希望这能有所帮助。

这个应该可以工作,但它会覆盖默认模板。实际上,我喜欢将轴标题包含在默认模板中(我在问题中擦掉的区域)。 - Felix
你应该绑定Text属性。请查看答案。我已经更新了它。 - rmojab63

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接