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 NCustomTooltipTool : NTooltipTool
{
public NCustomTooltipTool(NChartControl 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();
ClearTooltip();
}
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_RequestTooltip;
m_PrevShownTooltip = m_RequestTooltip;
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 SetTooltip(NPointF mousePosition, string tooltip)
{
if (m_PrevShownTooltip == tooltip)
{
return;
}
if (m_RequestTooltip == tooltip)
{
m_TimerShow.Stop();
m_TimerShow.Start();
m_MousePosition = mousePosition;
return;
}
m_RequestTooltip = tooltip;
}
protected override void ClearTooltip()
{
if (m_Label != null)
{
m_TimerShow.Stop();
m_Label.ParentPanel.ChildPanels.Remove(m_Label);
m_Label = null;
m_ChartControl.Refresh();
}
}
NChartControl m_ChartControl;
NLabel m_Label;
Timer m_TimerShow;
Timer m_TimerHide;
string m_PrevShownTooltip;
string m_RequestTooltip;
NPointF m_MousePosition;
}
private void Form1_Load(object sender, EventArgs e)
{
NCartesianChart chart = (NCartesianChart)nChartControl1.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);
nChartControl1.Controller.Tools.Add(new NCustomTooltipTool(nChartControl1));
}
}
}
Hope this helps - let us know if you meet any problems or have any questions.
Best Regards,
Nevron Support Team