SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy

We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

0
0

I deleted my prior question and instead provide code that reproduces the error. I just whipped up two SciChartSurfaces in xaml and bind to properties provided in code behind. Can you please take a look and see whether you also can RubberBandXyZoom but not correctly use ZoomPan? ZoomPan is not synced between the two charts. Its been a very frustrating couple hours….without finding the bug.

public partial class TestControl : UserControl
{
    private ILabelProvider _xAxisFormat;
    private string yAxisFormat;
    private ObservableCollection<IChartSeriesViewModel> _series1;
    private ObservableCollection<IChartSeriesViewModel> _series2;
    private DateRange _sharedXRange;

    public TestControl()
    {
        //SciChartSurface.SetLicenseKey(
        //    @"
        //    <LicenseContract>
        //      ....License Code goes here
        //    </LicenseContract>

        //    ");

        XAxisFormat = new DateTimeLabelProvider();
        YAxisFormat = "0.00";

        Series1 = new ObservableCollection<IChartSeriesViewModel>(new List<IChartSeriesViewModel>() { GenerateSampleLineSeries() });
        Series2 = new ObservableCollection<IChartSeriesViewModel>(new List<IChartSeriesViewModel>() { GenerateSampleLineSeries() });

        //set shared xRange
        SharedXRange = new DateRange((DateTime) Series1.First().DataSeries.XMin, (DateTime) Series1.First().DataSeries.XMax);

        InitializeComponent();
    }

    public ObservableCollection<IChartSeriesViewModel> Series1
    {
        get { return _series1; }
        set
        {
            _series1 = value;
        }
    }

    public ObservableCollection<IChartSeriesViewModel> Series2
    {
        get { return _series2; }
        set
        {
            _series2 = value;
        }
    }

    public DateRange SharedXRange
    {
        get { return _sharedXRange; }
        set
        {
            _sharedXRange = value;
        }
    }

    public ILabelProvider XAxisFormat
    {
        get { return _xAxisFormat; }
        set
        {
            _xAxisFormat = value;
        }
    }

    public string YAxisFormat
    {
        get { return yAxisFormat; }
        set
        {
            yAxisFormat = value;
        }
    }

    private IChartSeriesViewModel GenerateSampleLineSeries()
    {
        var seriesName = "TestLineSeries" + (new Random((int)DateTime.Now.Ticks)).Next();
        List<DateTime> timeStamps = new List<DateTime>();
        List<double> values = new List<double>();
        Random rand = new Random((int)DateTime.Now.Ticks);
        DateTime currentDt = DateTime.Now;
        double currentValue = 0;

        for (int index = 0; index < 1000; index++)
        {
            currentDt = currentDt.AddMinutes(1);
            currentValue = currentValue + (rand.NextDouble() - 0.5);

            timeStamps.Add(currentDt);
            values.Add(currentValue);
        }

        var dataSeries = new XyDataSeries<DateTime, double>();
        dataSeries.SeriesName = seriesName;
        dataSeries.Append(timeStamps, values);


        var renderSeries = new FastLineRenderableSeries() { Name = dataSeries.SeriesName, DataSeries = dataSeries, AntiAliasing = false, StrokeThickness = 2 };

        return new ChartSeriesViewModel(dataSeries, renderSeries);
    }
}


<UserControl x:Class="MattLibrary.ChartLibrary.Views.TestControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:s="http://schemas.abtsoftware.co.uk/scichart"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300"
         DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid>

    <Grid.RowDefinitions>
        <RowDefinition Height="1*"/>
        <RowDefinition Height="1*"/>
    </Grid.RowDefinitions>

    <s:SciChartSurface Grid.Row="0" SeriesSource="{Binding Series1}">

        <s:SciChartSurface.XAxis>
            <s:DateTimeAxis 
                            Visibility="Visible"
                            LabelProvider="{Binding XAxisFormat}" 
                            VisibleRange="{Binding SharedXRange}"
                            GrowBy="0.01, 0.01"/>
        </s:SciChartSurface.XAxis>

        <s:SciChartSurface.YAxis>
            <s:NumericAxis 
                            Visibility="Visible"
                            AxisAlignment="Right"
                            TextFormatting="{Binding YAxisFormat}" 
                            GrowBy="0.03, 0.03" 
                            AutoRange="Always"/>
        </s:SciChartSurface.YAxis>

        <s:SciChartSurface.ChartModifier>

            <s:ModifierGroup s:MouseManager.MouseEventGroup="SharedMouseGroup">

                <s:ZoomPanModifier IsEnabled="True" ReceiveHandledEvents="True" XyDirection="XDirection" ExecuteOn ="MouseLeftButton"/>
                <s:RubberBandXyZoomModifier IsEnabled="True" ReceiveHandledEvents="True" IsXAxisOnly="True" ExecuteOn="MouseRightButton"/>

            </s:ModifierGroup>
        </s:SciChartSurface.ChartModifier>

    </s:SciChartSurface>



    <s:SciChartSurface Grid.Row="1" SeriesSource="{Binding Series2}">

        <s:SciChartSurface.XAxis>
            <s:DateTimeAxis 
                            Visibility="Visible"
                            LabelProvider="{Binding XAxisFormat}" 
                            VisibleRange="{Binding SharedXRange}"
                            GrowBy="0.01, 0.01"/>
        </s:SciChartSurface.XAxis>

        <s:SciChartSurface.YAxis>
            <s:NumericAxis 
                            Visibility="Visible"
                            AxisAlignment="Right"
                            TextFormatting="{Binding YAxisFormat}" 
                            GrowBy="0.03, 0.03" 
                            AutoRange="Always"/>
        </s:SciChartSurface.YAxis>

        <s:SciChartSurface.ChartModifier>

            <s:ModifierGroup s:MouseManager.MouseEventGroup="SharedMouseGroup">

                <s:ZoomPanModifier IsEnabled="True" ReceiveHandledEvents="True" XyDirection="XDirection" ExecuteOn ="MouseLeftButton"/>
                <s:RubberBandXyZoomModifier IsEnabled="True" ReceiveHandledEvents="True" IsXAxisOnly="True" ExecuteOn="MouseRightButton"/>

            </s:ModifierGroup>
        </s:SciChartSurface.ChartModifier>



    </s:SciChartSurface>

</Grid>

  • You must to post comments
0
0

Hi Matt,

I was certain I replied to this but it must have gotten lost.

Chart Sychronization with ZoomPanModifier requires that you not only share mouse events, but also to bind the XAxis.VisibleRange of charts together.

I notice in your example you bind XAxis.VisibleRange but it is not a TwoWay binding. This can cause problems with SciChart.

Please update it to a TwoWay binding and it should work.

Best regards,
Andrew

  • bbmat
    I tried both, in fact I started out with 2-way binding but removed it as it did not work.
  • Andrew
    I’d suggest taking a look at our Sync Multi Chart Mouse sample and building up from scratch. It might help you to find the issue.. This implements zoompan synchronisation between two charts. The only required points are #1 to sync VisibleRange via TwoWay binding, #2 to set ZoomPanModifier.ReceiveHandledEvents = true and #3 of course to set MouseManager.MouseEventGroup on the parent ModifierGroups
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.