Group: Forum Members
Last Active: 9 Years Ago
Posts: 2,
Visits: 2
|
Hi,
I try to select points of my chart.
I draw an rectangle and obtains the coordinate of my rectangle.
Then, I use the method HitTest of my ChartControl, and obtains always no results. Here is my code :
void customDataZoom_EndDrag(object sender, EventArgs e) {
//PointDebut is define on mouse down PointFin = new Point(Cursor.Position.X, Cursor.Position.Y);
Point monPointDansGraphDeb = nChartControl1.PointToClient(PointDebut); Point monPointDansGraphFin = nChartControl1.PointToClient(PointFin);
NRectangleF maZone = new NRectangleF((float)monPointDansGraphDeb.X, (float)monPointDansGraphDeb.Y, Math.Abs((float)monPointDansGraphDeb.X - (float)monPointDansGraphFin.X), Math.Abs((float)monPointDansGraphDeb.Y - (float)monPointDansGraphFin.Y)); NHitTestResult[] mesPoints = nChartControl1.HitTest(maZone, true);
//--> mesPoints is alway empty
}
Thanks for your help. François
|
Group: Forum Members
Last Active: 9 Years Ago
Posts: 2,
Visits: 2
|
I contacted the support.
Here the solution :
using System; using System.Drawing; using System.Windows.Forms; using Nevron.Chart; using Nevron.Chart.WinForm; using Nevron.GraphicsCore;
namespace WindowsFormsApplication10 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
NRangeSelection m_RangeSelection; NPointSeries m_Point;
/// /// Overrides the standard data zoom tool. /// class NCustomDataZoom : NDataZoomTool { public NCustomDataZoom() { }
public override void OnEndDrag(object sender, MouseEventArgs e) { // just hide the range selection and repaint (no zooming is performed) base.HideRangeSelections(); base.Deactivate();
base.RepaintOverlay(); } }
private void Form1_Load(object sender, EventArgs e) { // create a chart with some dummy data NCartesianChart chart1 = (NCartesianChart)nChartControl1.Charts[0];
m_Point = new NPointSeries(); m_Point.DataLabelStyle.Visible = false; m_Point.UseXValues = true;
Random rand = new Random();
for (int i = 0; i < 100; i++) { m_Point.Values.Add(rand.Next(100)); m_Point.XValues.Add(rand.Next(100)); }
chart1.Series.Add(m_Point);
m_RangeSelection = new NRangeSelection(); chart1.RangeSelections.Add(m_RangeSelection);
nChartControl1.Controller.Tools.Add(new NSelectorTool());
NCustomDataZoom dataZoomTool = new NCustomDataZoom(); dataZoomTool.EndDrag +=new EventHandler(dataZoomTool_EndDrag); nChartControl1.Controller.Tools.Add(dataZoomTool);
}
void dataZoomTool_EndDrag(object sender, EventArgs e) { // get the selected ranges NRange1DD xRange = m_RangeSelection.HorizontalAxisRange; NRange1DD yRange = m_RangeSelection.VerticalAxisRange;
xRange.Normalize(); yRange.Normalize();
int count = m_Point.Values.Count; m_Point.FillStyles.Clear();
for (int i = 0; i < count; i++) { // color the data point in red if contained in the selection bool contained = xRange.Contains((double)m_Point.XValues[i]) && yRange.Contains((double)m_Point.Values[i]);
if (contained) { m_Point.FillStyles[i] = new NColorFillStyle(Color.Red); } }
nChartControl1.Refresh(); } } }
|