Jump to content
Software FX Community

Select a Range on the X Axis


Recommended Posts

After reading the docs and searching this forum, it doesn't look like one can select a range of X values.  Is this true?

As an example, say that I have an X axis with values ranging from 0 to 10 on a line chart.  I would like to:

  • Click '2' and drag the mouse to '7'.
  • I would like some visual feedback that '2' through ''7' are selected.
  • I would like to register an event listener that is called with the selected range..

If this is not possible, as a workaround my customer may be OK with zooming in on  the values as a way of selecting them.  For instance, just '2' through '7' would be displayed on the chart.  However, I do not see a way to find out what X values are currently being displayed.  How is this done?




Link to comment
Share on other sites

1) The UI you describe is not built-in into Chart FX, however you can implement it capturing the appropriate mouse events. All the API to translate from pixels to logical value (Axis.PixelToValue) and from logical value to pixel (Axis.ValueToPixel) exists.

2) The UserZooming event is fired when a zoom is about to occur. You receive the x,y coordinates for the start andend of the dragging rectangle. You can chose to handle this event yourself (set e.Handled = true) or let Chart FX do it.

3) You can, at any time after the chart is drawn, ask for the current range by calling Axis.GetScrollView

Link to comment
Share on other sites

As the mouse is moved you can trap this event and change any attributes of the chart you want, for instance, you can create an axis section that changes the color of the labels and has a background color to indicate the range. For example:

private AxisSection m_draggingSection;

On Mouse Down:

if (m_wantToSelect) {

 double x = chart1.AxisX.PixelToValue(e.X);  m_draggingSection = new AxisSection(x,x,Color.Red);  m_draggingSection.FontStyle = FontStyle.Bold;  chart1.AxisX.Sections.Add(m_draggingSection);}

 On MouseMove:

 if (m_draggingSection != null) { double x = chart1.AxisX.PixelToValue(e.X); x = Math.Max(x,m_draggingSection.From); m_draggingSection.To = x;  }

On MouseUp:

 if (m_draggingSection != null) { chart1.AxisX.Sections.Remove(m_draggingSection); m_draggingSection = null;  }

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...