PointLineSeries3D Point Annotation Tooltip

Need help in implementing some specific function to your LightningChart Ultimate powered application? Post a question and get code snippets from other LightningChart Ultimate community members.

Moderator: Queue Moderators

Post Reply
SESruss
Posts: 22
Joined: Wed Mar 12, 2014 6:36 pm

PointLineSeries3D Point Annotation Tooltip

Post by SESruss » Thu Dec 03, 2015 3:52 pm

As in the 'Surface Mouse Control' example with its mouse over annotation feature I am trying to replicate that for a PointLineSeries3D series object. I have done this with a 2D point line series. I am having problems with what I think should be a basic thing. I cannot get the MouseOverOn event to trigger.


As I am adding series items each series item is subscribing to the events and has an event handler. A breakpoint in either event handler never gets hit though.

Code: Select all

PointLineSeries3D pls = new PointLineSeries3D(_chart.View3D, Axis3DBinding.Primary, Axis3DBinding.Primary, Axis3DBinding.Primary);    
pls.MouseOverOn += MouseOnLine3D;
 pls.MouseOverOff += MouseOffLine3D;

Code: Select all

     void MouseOnLine3D(object sender, MouseEventArgs e)
        {}

SESruss
Posts: 22
Joined: Wed Mar 12, 2014 6:36 pm

Re: PointLineSeries3D Point Annotation Tooltip

Post by SESruss » Thu Dec 03, 2015 4:15 pm

Even something like in the 'Values tracking with markers' example would be fine but the SeriesEventMarker object appears to be for 2D only and searching the options that contain EventMarker does not seem to turn up any other event marker to use.

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: PointLineSeries3D Point Annotation Tooltip

Post by ArctionPasi » Thu Dec 03, 2015 7:36 pm

I'll try to write an example tomorrow.
LightningChart Support Team, PT

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: PointLineSeries3D Point Annotation Tooltip

Post by ArctionPasi » Fri Dec 04, 2015 2:06 pm

Here's the code for WPF:

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


using Arction.WPF.LightningChartUltimate;
using Arction.WPF.LightningChartUltimate.Views;
using Arction.WPF.LightningChartUltimate.Views.View3D;
using Arction.WPF.LightningChartUltimate.Series3D;
using Arction.WPF.LightningChartUltimate.Annotations; 


namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        LightningChartUltimate m_chart;
        Random m_rand = new Random(); 

        public MainWindow()
        {
            InitializeComponent();
            CreateChart();
        }

        /// <summary>
        /// Create chart.
        /// </summary>
        private void CreateChart()
        {
            //Create new chart 
            m_chart = new LightningChartUltimate();

            //Disable rendering, strongly recommended before updating chart properties
            m_chart.BeginUpdate();

            //Set active view
            m_chart.ActiveView = ActiveView.View3D;

            View3D v = m_chart.View3D;

            m_chart.ChartRenderOptions.FontsQuality = FontsRenderingQuality.High;

            int iSeriesCount = 5;
            for (int i = 0; i < iSeriesCount; i++)
            {
                AddSeriesWithData(
                    DefaultColors.SeriesWPF[i % DefaultColors.SeriesWPF.Length],
                    0, 100, i * 10);
            }
            //Add an annotation to show targeted point data 

            Annotation3D targetValueLabel = new Annotation3D(v, Axis3DBinding.Primary, Axis3DBinding.Primary, Axis3DBinding.Primary);
            targetValueLabel.TargetCoordinateSystem = AnnotationTargetCoordinates.AxisValues;
            targetValueLabel.LocationCoordinateSystem = CoordinateSystem.RelativeCoordinatesToTarget;
            targetValueLabel.LocationRelativeOffset.SetValues(40, -70);
            targetValueLabel.Visible = false;
            targetValueLabel.MouseInteraction = false;
            targetValueLabel.Style = AnnotationStyle.RoundedCallout;
            m_chart.View3D.Annotations.Add(targetValueLabel);

            m_chart.MouseMove += new MouseEventHandler(m_chart_MouseMove);
            
            v.ZAxisPrimary3D.SetRange(0, iSeriesCount * 10);

            v.LegendBox.Visible = false; 

            //Allow chart rendering
            m_chart.EndUpdate();

            gridMain.Children.Add(m_chart); 
        }


        void AddSeriesWithData(Color pointColor, double xMin, double xMax, double zAxisValue)
        {

            //Add 3D point-line series
            PointLineSeries3D pls = new PointLineSeries3D(m_chart.View3D, Axis3DBinding.Primary, Axis3DBinding.Primary, Axis3DBinding.Primary);
            pls.PointStyle.Shape = PointShape3D.Sphere;
            pls.PointStyle.Size.SetValues(2, 2, 2);
            pls.Material.DiffuseColor = pointColor;
            pls.LineVisible = true;
            pls.LineStyle.AntiAliasing = LineAntialias.Normal;
            pls.LineStyle.Color = CalcGradient(pointColor, Colors.Black, 50);
            pls.LineStyle.Width = 2f;
            pls.PointsVisible = true;
            pls.IndividualPointColors = true;
            pls.Title.Color = pointColor;
            pls.MouseInteraction = true;
            pls.MouseHighlight = MouseOverHighlight.None;

            m_chart.View3D.PointLineSeries3D.Add(pls);


            //Create data 
            int iPointCount = 31;
            SeriesPoint3D[] points = new SeriesPoint3D[iPointCount];
            double xStep = (xMax - xMin) / (double)(iPointCount - 1);


            for (int i = 0; i < iPointCount; i++)
            {
                points[i].X = xMin + (double)i * xStep;
                points[i].Y = 30 + m_rand.NextDouble() * 20.0;
                points[i].Z = zAxisValue;
                points[i].Color = pointColor;
            }
            pls.Points = points;

        }

        /// <summary>
        /// Mouse has been moved over the chart 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void m_chart_MouseMove(object sender, MouseEventArgs e)
        {
            m_chart.BeginUpdate();

            View3D v = m_chart.View3D;

            //Reset highlighted point colors  
            foreach (PointLineSeries3D pls in m_chart.View3D.PointLineSeries3D)
            {
                if (pls.Tag != null)
                {
                    //Restore color 
                    int iPointIndexUsedToBeTargeted = (int)pls.Tag;
                    pls.Points[iPointIndexUsedToBeTargeted].Color = pls.Title.Color;
                }
            }

            Annotation3D targetValueLabel = v.Annotations[0];
            targetValueLabel.Visible = false;

            //Get object under mouse if any 
            object o = m_chart.GetActiveMouseOverObject();


            if (o != null)
            {
                if (o is PointLineSeries3D)
                {
                    PointLineSeries3D pls = o as PointLineSeries3D;

                    int iPointIndex = pls.LastMouseHitTestIndex;
                    pls.Points[iPointIndex].Color = CalcGradient(pls.Title.Color, Colors.White, 50);
                    pls.Tag = iPointIndex; //Store info of point index that is highlighted 

                    SeriesPoint3D p = pls.Points[iPointIndex];

                    targetValueLabel.TargetAxisValues.SetValues(p.X, p.Y, p.Z);
                    targetValueLabel.Text = "Series index: " + v.PointLineSeries3D.IndexOf(pls).ToString()
                        + "\nPoint index: " + iPointIndex.ToString()
                        + "\nX=" + p.X.ToString("0.0") + " ; Y=" + p.Y.ToString("0.0") + " ; Z=" + p.Z.ToString("0.0");

                    targetValueLabel.Fill.Color = CalcGradient(pls.Title.Color, Colors.White, 90);
                    targetValueLabel.Fill.GradientColor = CalcGradient(pls.Title.Color, Colors.White, 50);
                    targetValueLabel.Visible = true;
                }
            }

            m_chart.EndUpdate();
        }

        public static System.Windows.Media.Color CalcGradient(System.Windows.Media.Color colorFrom, System.Windows.Media.Color colorTo, double positionPercents)
        {
            if (positionPercents <= 0)
                return colorFrom;
            else if (positionPercents >= 100)
                return colorTo;

            return System.Windows.Media.Color.FromArgb((byte)(colorFrom.A + (int)(positionPercents * (double)(colorTo.A - colorFrom.A) / 100.0)),
                                  (byte)(colorFrom.R + (int)(positionPercents * (double)(colorTo.R - colorFrom.R) / 100.0)),
                                  (byte)(colorFrom.G + (int)(positionPercents * (double)(colorTo.G - colorFrom.G) / 100.0)),
                                  (byte)(colorFrom.B + (int)(positionPercents * (double)(colorTo.B - colorFrom.B) / 100.0)));
        }
    }
}


When moving the mouse over the series points, it moves the annotation on that position, and displays the value in annotation's text. It also shows the over which series it is, and the point index.
Points tracking with mouse
Points tracking with mouse
points_tracking_3d.jpg (247.35 KiB) Viewed 18089 times
LightningChart Support Team, PT

SESruss
Posts: 22
Joined: Wed Mar 12, 2014 6:36 pm

Re: PointLineSeries3D Point Annotation Tooltip

Post by SESruss » Fri Dec 04, 2015 3:03 pm

Thanks so much that works perfectly.

Post Reply