Profile Picture

NHitTestResult.DataPointIndex is always 0 unless DataLabelStyle.Visible is true?

Posted By Noah Shipley 12 Years Ago
Author
Message
Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hi Noah,

We just tested a similar case with the following code, but we were not able to reproduce the problem. The DataPointIndex seems to be reported properly regardless of whether the data labels are visible or not. Are there any particular settings that we are missing?

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

      private void Form1_Load(object sender, EventArgs e)
      {
         NBoxAndWhiskersSeries bw = new NBoxAndWhiskersSeries();
         bw.DataLabelStyle.Visible = false;
         bw.UseXValues = true;

         nChartControl1.Charts[0].Series.Add(bw);
         nChartControl1.MouseMove += new MouseEventHandler(nChartControl1_MouseMove);

         AddBox(bw, 0, 100, 203, 60, 230);
         AddBox(bw, 1, 130, 230, 50, 250);
         AddBox(bw, 2, 110, 200, 60, 220);
         AddBox(bw, 3, 90, 220, 40, 230);
         AddBox(bw, 4, 110, 210, 30, 220);
         AddBox(bw, 5, 100, 205, 70, 230);
      }

      void AddBox(NBoxAndWhiskersSeries bw, double x, double lb, double ub, double lw, double uw)
      {
         bw.LowerBoxValues.Add(lb);
         bw.UpperBoxValues.Add(ub);            
         bw.LowerWhiskerValues.Add(lw);
         bw.UpperWhiskerValues.Add(uw);
         bw.XValues.Add(x);
      }

      void nChartControl1_MouseMove(object sender, MouseEventArgs e)
      {
         NHitTestResult hitTest = nChartControl1.HitTest(e.X, e.Y);

         if ((hitTest.ChartElement == ChartElement.DataPoint) && (hitTest.Series.GetSeriesType() == SeriesType.BoxAndWhiskers))
            this.Text = hitTest.DataPointIndex.ToString();
         else
            this.Text = string.Empty;
      }
   }


Best Regards,
Nevron Support Team



Noah Shipley
Posted 12 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 3, Visits: 1
I have added custom code to update a tooltip as the user mouses over data points within a series, however the value for DataPointIndex is wrong unless I am also showing data labels, which is ugly and seems like bug.

private void ChartControl_OnMouseMove(object sender, MouseEventArgs e)
{
NHitTestResult hitTest = _ChartControl.HitTest(e.X, e.Y);

if (hitTest.ChartElement == ChartElement.DataPoint)
{
var tip = new SuperToolTip() { AllowHtmlText = DefaultBoolean.True };

if (hitTest.Series.Name != "Line Series" && hitTest.Series.Name != "Point Series")
{
var title = tip.Items.AddTitle(hitTest.Series.Name);
}

//title.Appearance.TextOptions.HAlignment = HorzAlignment.Center;

switch (hitTest.Series.GetSeriesType())
{
//case SeriesType.Line:
// {
// var series = (NLineSeries)hitTest.Series;
// break;
// }

case SeriesType.BoxAndWhiskers:
{
var series = (NBoxAndWhiskersSeries) hitTest.Series;
tip.Items.Add("Index: " + hitTest.DataPointIndex);
tip.Items.AddSeparator();
tip.Items.Add("Low: " + ((double)series.LowerBoxValues[hitTest.DataPointIndex]).ToString(Model.DataFormatString));
tip.Items.Add("High: " + ((double)series.UpperBoxValues[hitTest.DataPointIndex]).ToString(Model.DataFormatString));
tip.Items.Add("Mean: " + ((double)series.AverageValues[hitTest.DataPointIndex]).ToString(Model.DataFormatString));
tip.Items.Add("Median: " + ((double)series.MedianValues[hitTest.DataPointIndex]).ToString(Model.DataFormatString));

break;
}

default:
{
if (hitTest.Series is NSeries)
{
var series = hitTest.Series as NSeries;

tip.Items.Add("Value: " + ((double) series.Values[hitTest.DataPointIndex]).ToString(Model.DataFormatString));
}

break;
}
}

var showArgs = new ToolTipControllerShowEventArgs() { SuperTip = tip };

_ChartControl.Widget.KFrame.ToolTipController.ShowHint(showArgs);
}
else
{
_ChartControl.Widget.KFrame.ToolTipController.HideHint();
}

}



Similar Topics


Reading This Topic