Hi Eli,
The following code shows how to override the standard
tooltip tool so that it shows a formatted label dynamically. In the next version we'll extend the control to support this as a build in feature:
using Nevron.
Chart;
using Nevron.
Chart.Windows;
using Nevron.
Chart.WinForm;
using Nevron.GraphicsCore;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[Serializable]
class NCustom
TooltipTool : N
TooltipTool
{
public NCustom
TooltipTool(N
ChartControl
chartControl)
{
m_
ChartControl =
chartControl;
m_TimerHide = new Timer();
m_TimerHide.Tick += OnTimerHideTick;
m_TimerHide.Interval = 2000;
m_TimerShow = new Timer();
m_TimerShow.Tick += OnTimerShowTick;
m_TimerShow.Interval = 1000;
}
private void OnTimerHideTick(object sender, EventArgs e)
{
m_TimerHide.Stop();
Clear
Tooltip();
}
private void OnTimerShowTick(object sender, EventArgs e)
{
if (m_Label == null)
{
m_Label = new NLabel();
m_Label.TextStyle.TextFormat = TextFormat.XML;
m_Label.UseAutomaticSize = true;
m_
ChartControl.Panels.Add(m_Label);
}
m_Label.Text = m_Request
Tooltip;
m_PrevShown
Tooltip = m_Request
Tooltip;
m_Label.Location = new NPointL(new NLength((int)m_MousePosition.X, NGraphicsUnit.Pixel), new NLength((int)m_MousePosition.Y, NGraphicsUnit.Pixel));
m_
ChartControl.Refresh();
m_TimerHide.Start();
}
protected override void Set
Tooltip(NPointF mousePosition, string
tooltip)
{
if (m_PrevShown
Tooltip ==
tooltip)
{
return;
}
if (m_Request
Tooltip ==
tooltip)
{
m_TimerShow.Stop();
m_TimerShow.Start();
m_MousePosition = mousePosition;
return;
}
m_Request
Tooltip =
tooltip;
}
protected override void Clear
Tooltip()
{
if (m_Label != null)
{
m_TimerShow.Stop();
m_Label.ParentPanel.ChildPanels.Remove(m_Label);
m_Label = null;
m_
ChartControl.Refresh();
}
}
N
ChartControl m_
ChartControl;
NLabel m_Label;
Timer m_TimerShow;
Timer m_TimerHide;
string m_PrevShown
Tooltip;
string m_Request
Tooltip;
NPointF m_MousePosition;
}
private void Form1_Load(object sender, EventArgs e)
{
NCartesian
Chart chart = (NCartesian
Chart)n
ChartControl1.
Charts[0];
NBarSeries bar = new NBarSeries();
bar.Values.Add(10);
bar.InteractivityStyles.Add(0, new NInteractivityStyle("Bar <b>1</b>"));
bar.Values.Add(20);
bar.InteractivityStyles.Add(1, new NInteractivityStyle("Bar <b>2</b>"));
bar.Values.Add(30);
bar.InteractivityStyles.Add(2, new NInteractivityStyle("Bar <b>3</b>"));
chart.Series.Add(bar);
n
ChartControl1.Controller.Tools.Add(new NCustom
TooltipTool(n
ChartControl1));
}
}
}
Hope this helps - let us know if you meet any problems or have any questions.
Best Regards,
Nevron Support Team