My previous example/question worked because I hard coded to use two charts each with their own chart modifiers as follows all in the same class.
_chartModifiers = new ModifierGroup();
MouseManager.SetMouseEventGroup(_chartModifiers, "MyGroup");
_chartModifiers2 = new ModifierGroup();
MouseManager.SetMouseEventGroup(_chartModifiers2, "MyGroup");
I am now building the ui that allows me to add and remove a graph from an items control. Each graph now binds to a view model to get its data and a parent class manages a collection of graphs (view models). I set the mouse event group in the constructor which is empty when I call SetMouseEventGroup. This causes some weird behavior when zooming as both graphs zoom together plus scrolling the yaxis scolls both yaxis at the same time and sometimes crashes.
Note: in my code now this gets call two times; once for each chart.
public GraphViewModel()
{
_chartModifiers = new ModifierGroup();
MouseManager.SetMouseEventGroup(_chartModifiers, "MyGroup");
}
private ModifierGroup _chartModifiers;
public ModifierGroup ChartModifiers
{
get { return _chartModifiers; }
set
{
_chartModifiers = value;
NotifyPropertyChanged(_chartModifierArgs);
}
}
I also tried to manage the number of items that I add to the mouse event group and while that stopped linking the zoom and yaxis scoll in this case I can no longer get the rollover to work.
ModifierGroup total = new ModifierGroup();
foreach (GraphViewModel www in vm.HistoricalHealthViewModel.DisplayedGraphs)
{
foreach (IChartModifier chartModifier in <a target="_blank" href="http://www.ChartModifiers.ChildModifiers)" target="_blank">www.ChartModifiers.ChildModifiers)</a>
{
// do not add the drag modifiers
if (!(chartModifier is YAxisDragModifier))
{
total.ChildModifiers.Add(chartModifier);
}
}
}
MouseManager.SetMouseEventGroup(total, "MyGroup");
Can you please suggest how to use the mouse event group?
- sdemooy asked 12 years ago
- You must login to post comments
Some properties and limitations of the MouseEventGroup:
- MouseManager.MouseEventGroup is designed to be set on a ModifierGroup and ensures that all child modifiers in that group publish their mouse events to other ModifierGroups that are listening
- This means that if your ModifierGroup contains XAxisDragModifiers, YAxisDragModifiers, Cursors, Rollovers, if any of these publish an event the corresponding type of modifier will also get the event on the other group
- It’s not currently possible to link a subset of modifiers, or an individual modifier with another
It sounds like what you’re trying to do is separate the other chart modifiers but link rollovers on multiple charts. Is this correct? Do you also want to link visibleRange (i.e. xaxis range) on multiple charts?
If so then take a two-fold approach:
Linking VisibleRange
This can be done in MVVM by binding two charts to a common property on a parent ViewModel. E.g.
<!-- Chart 1 bound to ChildViewModel1 --> <s:SciChartSurface> <s:SciChartSurface.XAxis> <s:NumericAxis VisibleRange="{Binding ParentViewModel.XVisibleRange, Mode=TwoWay}"/> </s:SciChartSurface.XAxis> </s:SciChartSurface> <!-- Chart 2 bound to ChildViewModel2 --> <s:SciChartSurface> <s:SciChartSurface.XAxis> <s:NumericAxis VisibleRange="{Binding ParentViewModel.XVisibleRange, Mode=TwoWay}"/> </s:SciChartSurface.XAxis> </s:SciChartSurface>
Linking Rollovers on Two Charts
Now with the above you could create a type derived from RolloverModifier and perform the link manually. Previously I posted a class called MasterRolloverModifier here: http://http://www.scichart.com/questions/question/share-rollover-between-two-charts/
public class MasterRolloverModifier : RolloverModifier { private IEnumerable<RolloverModifier> childModifiers; public MasterRolloverModifier() { } public void RegisterChildModifiers(params RolloverModifier[] childModifiers) { this.childModifiers = childModifiers; } // Forward on the mouse move event to child modifiers public override void OnModifierMouseMove(ModifierMouseArgs e) { base.OnModifierMouseMove(e); if (e.IsMaster) { foreach (var child in this.childModifiers) { e.IsMaster = false; child.OnModifierMouseMove(e); } } } }
If you attach one of these to all your charts (Dropping the MouseEventGroup) and in a parent viewmodel register rollover A with B (and vice versa) it will work.
Can you try this and let me know how you get on? If this does not solve the problem and you are stuck, please send us an email with any code (or a solution) to reproduce the issue. We can turn around fixes much more quickly when we can see the code.
- Andrew Burnett-Thompson answered 12 years ago
-
Thank you, this solution works very well.
- You must login to post comments
Please login first to submit.