Felix
Felix

Reputation: 2851

How to change the stringformat of Oxyplot track value?

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

Upvotes: 5

Views: 3960

Answers (2)

rmojab63
rmojab63

Reputation: 3631

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.

Upvotes: 3

Felix
Felix

Reputation: 2851

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}

Upvotes: 6

Related Questions