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)?
Asked
Active
Viewed 3,412 times
5
-
See https://oxyplot.userecho.com/en/communities/1/topics/583-trackerformatstring-question – Ian Botham Dec 27 '20 at 00:12
2 Answers
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}
{1}: {2:0.0}
{3}: {4:0.0}"/>
Please note the 

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
-
-
more discussion at http://discussion.oxyplot.org/forums/1-general/topics/583-trackerformatstring-question/ – Felix Nov 17 '17 at 07:48
-
1The current link to the discussion - https://oxyplot.userecho.com/en/communities/1/topics/583-trackerformatstring-question – Ian Botham Dec 27 '20 at 00:12
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
-