Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Display X and Y value when hovering on points of line (Read 4037 times)
William
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 2
Joined: Sep 6th, 2020
Display X and Y value when hovering on points of line
Sep 6th, 2020 at 7:29pm
Print Post  
Hi,
I am using line chart with Windows form. Do you know how to display X and Y value when hovering on points of line?

Thanks,
William
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Display X and Y value when hovering on points of line
Reply #1 - Sep 7th, 2020 at 6:30am
Print Post  
Hi,

You could set series' tooltips to the X,Y values of each point. If you implement the Series interface yourself, you can generate them automatically from GetLabel(LabelKinds.ToolTip) implementation.

These appear when mouse hovers over a point from the series, and not for segment points in between. If you need the latter, you'll need to show them via custom tooltip.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
JackMyers
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 1
Joined: Feb 9th, 2023
Re: Display X and Y value when hovering on points of line
Reply #2 - Feb 9th, 2023 at 10:31am
Print Post  
Hi,

I still do not understand how to implement this. I have a line chart with multiple series. What code do I need to use to display Y-axis values when hovering over the individual data points?

Thanks in advance,
Jack
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Display X and Y value when hovering on points of line
Reply #3 - Feb 9th, 2023 at 12:57pm
Print Post  
Hi,

E.g. try these two approaches in LineChart example:

Code
Select All
var yValues = new List<double> { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24 };
var yTooltips = yValues.Select(y => y.ToString()).ToList();
lineChart.Series.Add(
	new Series2D(
		new List<double> { 0,1,2,3,4,5,6,7,8,9,10,11 },
		yValues, yTooltips
	)
	{
		Title = "Series 2",
		SupportedLabels = LabelKinds.ToolTip /*| LabelKinds.InnerLabel*/
	});

lineChart.Series.Add(
	new YTooltip(
		new Series2D(
			new List<double> { 0,1,2,3,4,5,6,7,8,9,10,11 },
			new List<double> { 1,2,3,4,5,6,7,8,9,10,11,12 },
			labels
		)
		{ Title = "Series 1" }));

class YTooltip : Series
{
	public LabelKinds SupportedLabels =>
		series.SupportedLabels | LabelKinds.ToolTip;

	public string GetLabel(int index, LabelKinds kind)
	{
		if (kind == LabelKinds.ToolTip)
			return series.GetValue(index, 1).ToString();

		return series.GetLabel(index, kind);
	}

	public YTooltip(Series series)
	{
		Debug.Assert(series.Dimensions >= 2);
		this.series = series;
	}

	public int Size => series.Size;

	public int Dimensions => series.Dimensions;

	public string Title => series.Title;

	public double GetValue(int index, int dimension)
	{
		return series.GetValue(index, dimension);
	}

	public bool IsEmphasized(int index) { return series.IsEmphasized(index); }

	public bool IsSorted(int dimension) { return false; }

	public event EventHandler DataChanged;

	Series series;
} 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint