How to hide Element from HitTest?


Author
Message
Alina Voskova
Alina Voskova
Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)
Group: Forum Members
Posts: 43, Visits: 1
I have a NAxisConstLine that moves with a mouse. And also I need to handle the situation, when user clicks on DataPoint. But the HitTest always shows me my ConstLine and never DataPoint. How I can hide the ConstLine from HitTest? Or maybe anyone can tell me how to solve this problem another way.
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K

Hi Alina,

You can use axis cursors instead of const lines - they are faster and do not affect the HiTest. You can check the following example:

All Examples\Interactivity\Tools\Data Cursor Tool

Hope this helps - let us know if you meet any problems.



Best Regards,
Nevron Support Team


Alina Voskova
Alina Voskova
Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)
Group: Forum Members
Posts: 43, Visits: 1
Thank you, I think cursor is exactly what I need, but I can't make it work in my program! I use the following code:
public void OnChartMouseMove(object sender, MouseEventArgs e)
{
NAxis xAxis = _cartesianChart.Axis((int)StandardAxis.PrimaryX);
if (xAxis.Cursors.Count == 0)
{
NAxisCursor cursor = new NAxisCursor();
cursor.BeginEndAxis = (int)StandardAxis.PrimaryY;
cursor.StrokeStyle = new NStrokeStyle(1, Color.Red);
cursor.SynchronizeOnMouseAction = MouseAction.Move;
cursor.ValueSnapper = new NAxisRulerClampSnapper();
xAxis.Cursors.Add(cursor);
}
NAxis yAxis = _cartesianChart.Axis((int)StandardAxis.PrimaryY);
if (yAxis.Cursors.Count == 0)
{
NAxisCursor cursor = new NAxisCursor();
cursor.BeginEndAxis = (int)StandardAxis.PrimaryX;
cursor.StrokeStyle = new NStrokeStyle(1, Color.Red);
cursor.SynchronizeOnMouseAction = MouseAction.Move;
cursor.ValueSnapper = new NAxisRulerClampSnapper();
yAxis.Cursors.Add(cursor);
}
_cartesianChart.Refresh();
}
public void OnChartMouseLeave(object sender, EventArgs e)
{
_cartesianChart.Axis(StandardAxis.PrimaryX).Cursors.Clear();
_cartesianChart.Axis(StandardAxis.PrimaryY).Cursors.Clear();
}
For OY-Axis cursor always has a value 0, for OX-Axis I can't say, because I don't see its cursor. It looks like I need to set the cursor value manually.
What I do wrong?
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K

Hi Alina,

In general you need to two more things to make this work:

1. Add a NDataCursorTool to the chart controller.
2. Specify active chart.

The following code shows how to achieve this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Nevron.Chart;
using Nevron.GraphicsCore;
using Nevron.Chart.WinForm;

namespace WindowsFormsApplication7
{
 public partial class Form1 : Form
 {
  public Form1()
  {
   InitializeComponent();
  }

  NChart _cartesianChart;

  private void Form1_Load(object sender, EventArgs e)
  {
   _cartesianChart = (NCartesianChart)nChartControl1.Charts[0];

   NBarSeries bar = new NBarSeries();

   bar.Values.Add(10);
   bar.Values.Add(20);
   bar.Values.Add(30);

   _cartesianChart.Series.Add(bar);

   nChartControl1.MouseMove +=new MouseEventHandler(nChartControl1_MouseMove);
   nChartControl1.MouseLeave +=new EventHandler(nChartControl1_MouseLeave);

   nChartControl1.Controller.Selection.SelectedObjects.Add(_cartesianChart);
   nChartControl1.Controller.Tools.Add(new NDataCursorTool());
  }

  public void nChartControl1_MouseMove(object sender, MouseEventArgs e)
  {
   NAxis xAxis = _cartesianChart.Axis((int)StandardAxis.PrimaryX);
   if (xAxis.Cursors.Count == 0)
   {
    NAxisCursor cursor = new NAxisCursor();
    cursor.BeginEndAxis = (int)StandardAxis.PrimaryY;
    cursor.StrokeStyle = new NStrokeStyle(1, Color.Red);
    cursor.SynchronizeOnMouseAction = MouseAction.Move;
    cursor.ValueSnapper = new NAxisRulerClampSnapper();
    xAxis.Cursors.Add(cursor);
   }
   NAxis yAxis = _cartesianChart.Axis((int)StandardAxis.PrimaryY);
   if (yAxis.Cursors.Count == 0)
   {
    NAxisCursor cursor = new NAxisCursor();
    cursor.BeginEndAxis = (int)StandardAxis.PrimaryX;
    cursor.StrokeStyle = new NStrokeStyle(1, Color.Red);
    cursor.SynchronizeOnMouseAction = MouseAction.Move;
    cursor.ValueSnapper = new NAxisRulerClampSnapper();
    yAxis.Cursors.Add(cursor);
   }
   _cartesianChart.Refresh();
  }
  public void nChartControl1_MouseLeave(object sender, EventArgs e)
  {
   _cartesianChart.Axis(StandardAxis.PrimaryX).Cursors.Clear();
   _cartesianChart.Axis(StandardAxis.PrimaryY).Cursors.Clear();
   nChartControl1.Invalidate();
  }
 }
}

Let us know if you meet any problems.



Best Regards,
Nevron Support Team


Alina Voskova
Alina Voskova
Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)
Group: Forum Members
Posts: 43, Visits: 1
One more question about cursor. How I can make the element (DataPoint with its DataLabel) render over the cursor line? This DataPoint moves with the cursor and shows the corresponding value of line series on the chart.
And one more problem: Our chart have tools for scaling: NDataZoomTool, NSelectorTool, NAxisScrollTool. When I make the scale larger and then click the reset button, cursor stops and doesn't follow the mouse. It begins to move only when I click inside the chart. What is this? I have cursor.SynchronizeOnMouseAction = MouseAction.Move | MouseAction.Down | MouseAction.Up.
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K

Hi Ereona,

You cannot paint the data point over the cursor as cursors are painted in overlay mode for performance reasons. Regarding the stop of the cursor update - the cursors will follow the mouse only when the current selection contains the chart that defines them. When you click outside the chart the current selection does not contain it and therefore the cursors stop to update (notice in the that the code above the current selection is configured via code:

nChartControl1.Controller.Selection.SelectedObjects.Add(_cartesianChart);

We recommend to use this approach and remove the selector tool from the controller.

Hope this helps - let us know if you meet any problems.


 



Best Regards,
Nevron Support Team


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search