Group: Forum Members
Last Active: 3 Months Ago
Posts: 86,
Visits: 221
|
Hi Experts, I have a HeatMapChart like the following: now I want to show a label with the X and Y and the according values when the Mouse hovers over the chart. Is there an easy way to do so? I tried it with an NRectangularCallout together with a new Controller: [Serializable] public class MyDataLabelTool : NTool { #region Constructor public MyDataLabelTool() { } #endregion
#region Overrides
public override void OnMouseMove(object sender, Nevron.Chart.Windows.NMouseEventArgs e) { NControlView view = (NControlView)this.GetView(); NHitTestCacheService hitTestService = GetView().GetServiceOfType(typeof(NHitTestCacheService)) as NHitTestCacheService; if (hitTestService == null) return;
NHitTestResult result = new NHitTestResult(hitTestService.HitTest(new NPointF(e.X, e.Y)) as NChartNode); INMouseService mouseService = (INMouseService)GetView().GetServiceOfType(typeof(INMouseService)); if (result.ChartElement == ChartElement.DataPoint) { mouseService.Cursor = Cursors.SizeAll; int fX = result.HeatMapDataPointX; int fY = result.HeatMapDataPointY;
int iIndex = result.DataPointIndex; double fValue = ((NHeatMapSeries)(result.Chart.Series[0])).Data.Values[iIndex]; Console.WriteLine("Index: " + iIndex.ToString() + " X:" + fX.ToString() + " Y:" + fY.ToString() + " Value: " + fValue.ToString("N2")); // up to here it is working => on the output window the correct values are displayed
NRectangularCallout m_RectangularCallout = (NRectangularCallout)result.Chart.Series[0].Tag; NDataPointAnchor anchor = new NDataPointAnchor(result.Chart.Series[0], iIndex, ContentAlignment.MiddleCenter, StringAlignment.Center); m_RectangularCallout.Anchor = anchor; // anchor still has no series at this point (series==null) m_RectangularCallout.Text = " X:" + fX.ToString() + " Y:" + fY.ToString() + " Value: " + fValue.ToString("N2"); m_RectangularCallout.Visible = true;
// no error here - but also no Label } else { mouseService.Cursor = mouseService.DefaultCursor; }
} #endregionThe Controller itself seems to get the correct values when the mouse is moved - but the anchor point seems to be wrong. After doing: NDataPointAnchor anchor = new NDataPointAnchor(result.Chart.Series[0], iIndex, ContentAlignment.MiddleCenter, StringAlignment.Center);the anchor.Series is still null - and no Label is shown.
Thanks for helping, Best regards, Joern
|