【问题标题】:How to change the stringformat of Oxyplot track value?如何更改 Oxyplot 跟踪值的字符串格式?
【发布时间】:2017-02-21 01:50:25
【问题描述】:

如果我更改轴的字符串格式,它适用于轴(参见图片的黑色圆圈)。但是如何更改轨道值的字符串格式(红色圆圈)?

【问题讨论】:

标签: wpf xaml string-formatting axis-labels oxyplot


【解决方案1】:

我想根据拉明对我的提示回答我自己的问题。

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

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

请注意我的代码中的&amp;#x0a;,它是如何在 XAML 中输入换行符的。

还请注意开头的 {},这是 XAML 中的一种转义字符。

如果在 c# 中,它只是:

{0}\n{1}: {2:0.0}\n{3}: {4:0.0}

【讨论】:

【解决方案2】:

你应该设置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>

希望对你有帮助。

【讨论】:

  • 这应该可以,但它会覆盖默认模板。我实际上喜欢将轴标题包含在默认模板中(我在问题的图片中删除的区域)。
  • 您应该绑定 Text 属性。见答案。我更新了。
猜你喜欢
  • 2014-09-15
  • 1970-01-01
  • 2019-07-17
  • 2016-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-10
相关资源
最近更新 更多