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.
- [email protected] asked 10 years ago
- last edited 10 years ago
- You must login to post comments
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
- Andrew Burnett-Thompson answered 10 years ago
- last edited 10 years ago
-
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
-
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.
-
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
-
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 login to post comments
Please login first to submit.