wpfxamlstring-formattingaxis-labelsoxyplot

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


Solution

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