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

问题描述 投票:0回答:3

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

enter image description here

wpf xaml string-formatting axis-labels oxyplot
3个回答
6
投票

我想根据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}

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>

希望有帮助。


0
投票

private PlotModel CreatePlotModel(字符串标题, OxyColor 颜色) { varplotModel = new PlotModel { };

  // Data series
  var series = new LineSeries
  {
      Title = title,                
      TrackerFormatString = "{0}\nTime: {2:0.000}\nValue: {4:0.000}",
      Color = color
  };
  plotModel.Series.Add(series);

  
  plotModel.Legends.Add(new OxyPlot.Legends.Legend
  {
      LegendPosition = OxyPlot.Legends.LegendPosition.TopCenter,
      LegendTextColor = color
  });
  

  return plotModel;

}

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.