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

Hi
I want to plot line chart on BoxAnnotation, so that BoxAnnotion become as a container.
i.e dataSeries.Append(100, 100);
dataSeries.Append(200, 150;
on BoxAnnotation
Please have a lool into the picture.

Images
  • You must to post comments
0
1

Hi there,

If I understand correctly, what you want to achieve is to have a chart inside a BoxAnnotation, so you can drag this around the underlying chart. Is that correct?

If so, this could be achieved by re-templating the BoxAnnotation ControlTemplate to hold another chart.

The template for BoxAnnotation is quite simple. It specifies a Border with templateBindings to BorderBrush, BorderThickness, Background. Try this, for instance:

<BoxAnnotation>
   <BoxAnnotation.Template>
      <!-- Retemplate the BoxAnnotation to be anything you want -->
      <ControlTemplate TargetType="{x:Type BoxAnnotation}">
         <Border x:Name="PART_BoxAnnotationRoot" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}">
            <!-- Place a SciChartSurface inside the BoxAnnotation Border -->
            <s:SciChartSurface>
                <s:SciChartSurface.RenderableSeries>
                   <!-- Set DataContext of annotation equal to a ViewModel so you can bind to DataSeries property -->
                   <s:FastLineRenderableSeries DataSeries="{Binding DataSeries}"/>
                </s:SciChartSurface.RenderableSeries>
                <s:SciChartSurface.YAxis>
                   <s:NumericAxis/>
                </s:SciChartSurface.YAxis>
                <s:SciChartSurface.XAxis>
                   <s:NumericAxis/>
                </s:SciChartSurface.XAxis>
            </s:SciChartSurface>
         </Border>
      </ControlTemplate>
   </BoxAnnotation.Template>
</BoxAnnotation>

I’ve not tested the above code but it conveys the concept. You can template the BoxAnnotation to be anything you want, even placing a chart inside it. Just beware that you must set the DataContext of your BoxAnnotation equal to something (like a viewmodel) so the inner ScichartSurface can see this datacontext to bind to DataSeries.

Let me know if it helps, and post pictures of the result if you achieve it!

Best regards,
Andrew

  • sonu91@gmail.com
    Hi Andrew,Thanks for your quick response, I am trying to do the requirement according to the given solution but I am getting "Unable to Apply the Control Template. PART_BoxAnnotationRoot is missing or of the wrong type" error. As it given for xaml file but I need to implement in viewModel,Plz help
  • sonu91@gmail.com
    Hi Andrew, Can I get the same xaml code as a C# code ,So That I can test in Viewmodel.I hope it will work.
  • Andrew
    Oh sorry, I have edited my code in answer. Try adding x:Name="PART_BoxAnnotationRoot" to the Border. To do the same in Code-behind would be nearly impossible, I would strongly recommend altering control templates in Xaml! However, if you wanted to go this route you can use this technique: http://stackoverflow.com/a/17595059/303612
  • sonu91@gmail.com
    Thak you Andrew,Yes I had added the same & It was working in xaml code, But I have to make it dynymic at ViewModel side,let me try the other solution.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.