5

If I change the stringformat of axis, it works for the axis (see the black circle of the picture). But how can I change the stringformat of the track value (the red circle)?

enter image description here

Felix
  • 2,673
  • 3
  • 30
  • 38

2 Answers2

5

I'd like to answer my own question based on Ramin's hint to me.

I dug into the source code a little bit, and found out there is a TrackerFormatString that I can change:

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

Please note the &#x0a; in my code, that how a newline char is input in XAML.

Please also note the {} in the very beginning, that's kind of escape char in XAML.

if in c#, it's just:

{0}\n{1}: {2:0.0}\n{3}: {4:0.0}
Felix
  • 2,673
  • 3
  • 30
  • 38
3

You should set DefaultTrackerTemplate. Here a small example that shows you the way:

<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>

Hope it helps.

rmojab63
  • 3,513
  • 1
  • 15
  • 28
  • This should work, but it overwrites the default template. I actually like the axis titles to be included as in the default template (the area I erased in the picture in my question). – Felix Feb 21 '17 at 13:48
  • You should bind the Text property. See the answer. I updated it. – rmojab63 Feb 21 '17 at 14:06