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!

1
0

How do you enumerate child charts on a chart group?

My purpose is to try to call ZoomExtents() for each chart in a group after I an event is triggered from the ViewModel which reflects on code-behind of the Window.

Thanks.

  • You must to post comments
1
0

Hi Jayson,

You can’t enumerate the charts easily, as they are templated. If you really need to do this I would suggest looking at this article on ItemsControl.GetContainerFromItem.

However, sounds like you just want to zoom to extents on the child charts, am I right?

If so, we’ve literally just added the ability to Zoom Extents in our own Create Multi Pane Stock Charts example in v3.1, as we omitted this feature in v3.0. The code we’ve added to do this is below:

I’ve omitted irrelevant parts of the code.

1. The SciStockChart in the SciChartGroup ItemTemplate binds to a ViewportManager

<!-- Databinds a SciChartGroup to a list of ChartPaneViewModels -->
<!-- Child chart panes are generated using the ItemTemplate below -->
<s:SciChartGroup ... >
    <s:SciChartGroup.ItemTemplate>
        <DataTemplate>
                        
            <!-- Databinds each child SciStockChart ... -->
            <s:SciStockChart  ...  
                              ViewportManager="{Binding ParentViewModel.ViewportManager}"
                              SeriesSource="{Binding ChartSeriesViewModels}">
                            
                ...
                            
            </s:SciStockChart>
        </DataTemplate>
    </s:SciChartGroup.ItemTemplate>
</s:SciChartGroup>

2. The ParentViewModel (shared by all charts) contains a ViewportManager instance

private IViewportManager _viewportManager;_viewportManager = new DefaultViewportManager();

public IViewportManager ViewportManager { get { return _viewportManager; } }

3. The ZoomExtents operation can now be performed via the ViewportManager

// Inside your ViewModel which hosts the ViewportManager
private void ZoomExtents()
{
    ViewportManager.AnimateZoomExtents(TimeSpan.FromMilliseconds(500));
}

That’s it! You can then control the viewport, zoom to extents etc… directly from your ViewModel

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.