Hi,
After the chart is added with data I want to switch between using the ZoomExtents method and manually setting the AutoRange = Never and setting the VisibleRange. It works using either of them, but after using the ZoomExtents method the axis range is never adjusted to the VisibleRange. Am I doing something wrong or is not possible ?
Using SciChart 3.1.0
Best regards
Marius
- Marius Mathisen asked 9 years ago
- You must login to post comments
OK i think there is a really simple solution to this
Please see Axis.VisibleRange – a Note about Dependency Property Precedence
AxisBase.VisibleRange is a DependencyProperty, it is therefore subject to Dependency Property Precedence in WPF. See the MSDN Documentation for more details.
Internally, SciChart sets the AxisBase.VisibleRangeProperty using the
Local Value precedence in some places. We must do this as
ChartModifiers, and AutoRange need to update the
AxisBase.VisibleRange.This means that in some cases, style setters and templated properties
setting Axis.VisibleRange will not appear to work. For this reason we
recommend that any bindings to VisibleRange are a TwoWay binding to a
ViewModel property:<s:NumericAxis VisibleRange="{Binding AxisVisibleRange, Mode=TwoWay}"/>
- Andrew Burnett-Thompson answered 9 years ago
-
Thank you very much Andrew! Simple solution and it works! : - )
- You must login to post comments
Hi Marius,
The first thing I would say is ‘does the problem occur in the latest version?’. v3.1 was released almost a year ago and a lot of bugs have been fixed since then. See our release notes to see how busy we’ve been!
Secondly, the way to switch between AutoRange.Always and AutoRange.Never is to handle a click event and and set the AxisBase.AutoRange property, e.g. imagine this workflow:
- Set chart AutoRange.Always, the chart always zooms to fit the data
- On mouse-down of a chart, set AutoRange.Never. Now allow the user to zoom and pan using our modifiers
- On mouse-double-click of a chart, set AutoRange.Always again
This way the user can always interact with an autoranged-chart and simply double-clicking resets the behaviour back to autorange after they have zoomed and panned.
Have a look at these related FAQs as they may also give you some ideas.
- How can I Zooming my chart in real time
- Zooming in real time charts when AutoRange is enabled?
- Custom ZoomExtentsModifier to enable AutoRange on Realtime Chart
Best regards,
Andrew
- Andrew Burnett-Thompson answered 9 years ago
- You must login to post comments
Hi Andrew,
Thank you very much for your quick response!
I am now using latest version 3.5 and having the same issues.
- Adding dummy data, setting AutoRange = Never and VisibleRange = -1,1 Works!
- Clicking button, setting AutoRange = Never and VisibleRange = -100,100 Works!
- Zooming or double click to fit (using modifiers) Works!
- Clicking button, setting AutoRange = Never and VisibleRange = -100,100 DO NOT WORK!
If I use the modifiers or uses the ZoomExtents I am not able to manually set the VisibleRange.
Best regards
Marius
Test project:
Code behind:
public partial class MainWindow
{
public ViewModel ViewModel { get; set; }
public MainWindow()
{
ViewModel = new ViewModel
{
AutoRange = AutoRange.Once,
VisibleRange = new DoubleRange(0, 0),
ChartSeries = new ObservableCollection<IChartSeriesViewModel>()
};
InitializeComponent();
var data = new List<double> { 0, 2, 4, 6, 8 };
var chartData = new XyDataSeries<double, double>();
for (var i = 0; i < data.Count; i++)
chartData.Append(i, i);
var fastLineSeries = new FastLineRenderableSeries
{
SeriesColor = Colors.Red,
StrokeThickness = 1,
PointMarker = new EllipsePointMarker { Width = 7, Height = 7, Fill = Colors.Yellow }
};
var chartSerie = new ChartSeriesViewModel(chartData, fastLineSeries);
ViewModel.ChartSeries.Add(chartSerie);
ViewModel.AutoRange = AutoRange.Never;
ViewModel.VisibleRange = new DoubleRange(-1, 1);
}
private void ButtonChange_OnClick(object sender, RoutedEventArgs e)
{
ViewModel.AutoRange = AutoRange.Never;
ViewModel.VisibleRange = new DoubleRange(-100, 100);
}
Xaml:
<Window.Resources>
<Style x:Key="SciChartSurfaceStyle" TargetType="s:SciChartSurface">
<Setter Property="Background" Value="WhiteSmoke"/>
<Setter Property="Padding" Value="20"/>
<Setter Property="Foreground" Value="DarkOrchid"/>
<Setter Property="FontSize" Value="20"/>
<Setter Property="FontFamily" Value="Arial Black"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
<Style x:Key="GridLinesPanelStyle" TargetType="s:GridLinesPanel">
<Setter Property="Background" Value="White"/>
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="BorderBrush" Value="SteelBlue"/>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<DockPanel Grid.Row="0">
<Button Click="ButtonChange_OnClick">Set VisibleRange</Button>
</DockPanel>
<GroupBox Header="Graph" Grid.Row="2">
<s:SciChartSurface
x:Name="SciChart"
SeriesSource="{Binding Path=ViewModel.ChartSeries}"
ClipModifierSurface="True"
Style="{StaticResource SciChartSurfaceStyle}"
GridLinesPanelStyle="{StaticResource GridLinesPanelStyle}"
>
<s:SciChartSurface.XAxes>
<s:NumericAxis AxisAlignment="Bottom" BorderThickness="0,1,0,0"/>
</s:SciChartSurface.XAxes>
<s:SciChartSurface.YAxes>
<s:NumericAxis x:Name="NumericYAxes"
AxisAlignment="Left" BorderBrush="White" BorderThickness="1,0,0,0"
AutoRange="{Binding Path=ViewModel.AutoRange}"
VisibleRange="{Binding Path=ViewModel.VisibleRange}"
TickTextBrush="DarkBlue"
TextFormatting="0.######"
GrowBy="{Binding Path=ViewModel.YAxisGrowBy}"/>
</s:SciChartSurface.YAxes>
<s:SciChartSurface.ChartModifier>
<s:ModifierGroup>
<s:RubberBandXyZoomModifier IsEnabled="True" IsXAxisOnly="False" ZoomExtentsY="False" IsAnimated="True"/>
<s:ZoomExtentsModifier ExecuteOn="MouseDoubleClick"/>
<s:ZoomPanModifier IsEnabled="True" ExecuteOn="MouseRightButton"/>
</s:ModifierGroup>
</s:SciChartSurface.ChartModifier>
</s:SciChartSurface>
</GroupBox>
</Grid>
- Marius Mathisen answered 9 years ago
- You must login to post comments
Please login first to submit.