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!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

1
0
<s:SciChartGroup Grid.Row="1" Name="charts" 
                     ItemsSource="{Binding ChartPaneViewModels}" 
                     s:ThemeManager.Theme="{Binding ElementName=ThemeCombo, Path=SelectedItem}"
                     ItemContainerStyle="{StaticResource ChartPaneStyle}">
        <s:SciChartGroup.ItemTemplate>
            <DataTemplate x:Name="template">
                <s:SciStockChart Padding="0" 
                                 BorderThickness="0,0,1,1" *** Annotations="{Binding TradeAnnotations}"<--How to binding this to first chart? ***
                                 IsXAxisVisible="{Binding IsFirstChartPane}" 
                                 IsPanEnabled="{Binding ParentViewModel.IsPanEnabled}"
                                 IsRubberBandZoomEnabled="{Binding ParentViewModel.IsZoomEnabled}" 
                                 VerticalChartGroupId="{Binding ParentViewModel.VerticalChartGroupId}"    
                                 ViewportManager="{Binding ParentViewModel.ViewportManager}" IsRolloverEnabled="True" 
                                 SeriesSource="{Binding ChartSeriesViewModels}">
                    <s:SciStockChart.XAxis>
                        <s:CategoryDateTimeAxis Name="xAxis" 
                                                TextFormatting="MM-dd HH:mm:ss" 
                                                VisibleRange="{Binding ParentViewModel.XVisibleRange, Mode=TwoWay}"
                                                DrawMajorBands="False"
                                                DrawMinorGridLines="True"
                                                GrowBy="0,0.05"/>
                    </s:SciStockChart.XAxis>
                    <s:SciStockChart.XAxisStyle>
                        <Style TargetType="s:CategoryDateTimeAxis">
                            <Setter Property="DrawMajorBands" Value="True"/>
                            <Setter Property="DrawMinorGridLines" Value="False"/>
                            <Setter Property="VisibleRange" Value="{Binding ParentViewModel.XVisibleRange, Mode=TwoWay}"/>
                            <Setter Property="GrowBy" Value="0, 0.05"/>
                        </Style>
                    </s:SciStockChart.XAxisStyle>
                    <s:SciStockChart.YAxes>
                        <s:NumericAxis AutoRange="Always"
                            Id="Y2"/>
                    </s:SciStockChart.YAxes>
                    <s:SciStockChart.YAxisStyle>
                        <Style TargetType="s:NumericAxis">
                            <Setter Property="AutoRange" Value="Always"></Setter>
                            <Setter Property="TextFormatting" Value="{Binding YAxisTextFormatting}"/>
                            <Setter Property="MinorsPerMajor" Value="{Binding IsFirstChartPane, Converter={StaticResource MinorsPerMajorConverter}}"/>
                            <Setter Property="MaxAutoTicks" Value="{Binding IsFirstChartPane, Converter={StaticResource MaxAutoTicksConverter}}"/>
                            <Setter Property="GrowBy" Value="{Binding IsFirstChartPane, Converter={StaticResource GrowByConverter}}"/>
                        </Style>
                    </s:SciStockChart.YAxisStyle>
                </s:SciStockChart>
            </DataTemplate>
        </s:SciChartGroup.ItemTemplate>
    </s:SciChartGroup>
  • You must to post comments
0
0

Hi Hwa,

You have a collection of ChartPaneViewModels right?

Then you can expose an AnnotationCollection on a chart pane viewmodel, e.g.

public class ChartPaneViewModel
{
    private AnnotationCollection _annotationCollection = new AnnotationCollection();

    public ChartPaneViewModel()
    {
         // Then only for first ChartPaneViewModel add one annotation
        _annotationCollection.Add(new TextAnnotation() { Text="Hello!", X1=0, Y1=100};
    }
     public AnnotationCollection { get { return _annotationCollection; } } 
}

Then you can bind to it in the View like this

<s:SciChartGroup 
                        ... >
        <s:SciChartGroup.ItemTemplate>
            <DataTemplate x:Name="template">
                <s:SciStockChart Padding="0"
                                 ...
                                 Annotations="{Binding AnnotationCollection}>
                           ...
                </s:SciStockChart>
            </DataTemplate>
        <s:SciChartGroup.ItemTemplate>
 </s:SciChartGroup>

If you want to extend this to be more MVVM friendly, please see this article: Editing annotations and keeping track of them in an mvvm application

Best regards,
Andrew

  • You must to post comments
0
0

Hi Andrew
Thanks for your reply .

 public class AbtChartControl_ViewModel : BaseViewModel
{
    public AbChartControl_ViewModel(Strategy s)
    {
        s.AddTradeFlagHandler += AddAnnotation;
        _annotations = new AnnotationCollection();
        _chartPaneViewModels.Add(new OhlcPaneViewModel(this, s) { IsFirstChartPane = true });
        _chartPaneViewModels.Add(new VolumePaneViewModel(this, s);
    }
    private void AddAnnotation(TradeFlagEventArgs e)
    {
       IAnnotation annotation;
       if (e.Direction == EDirection.Buy)
           annotation = new BuyMarkerAnnotation() { X1 = e.Datetime, Y1 = e.Price, };
       else
           annotation = new SellMarkerAnnotation() { X1 = e.Datetime, Y1 = e.Price };
       this._annotations.Add(annotation);
    }
    private AnnotationCollection _annotations;
    public AnnotationCollection TradeAnnotations
    {
        get { return _annotations; }
        set
        {
            _annotations = value;
            RaisePropertyChanged("TradeAnnotations");
        }
    }

}

Then I bind to View as you , run it , An exception occurs :
System.NullReferenceException

  • You must to post comments
0
0

On not ItemTemplate, Running normally , But I do not know much about modifier , I don’t know set
Pan, Zoom , VisibleRange , etc.

  • Hwa Fun
    to replace a version is no problem
  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.