How to add a C1LineMarker to C1FlexChart in code

Posted by: scadavantagesupport on 19 September 2017, 8:02 am EST

  • Posted 19 September 2017, 8:02 am EST

    I want to add a line marker to a C1FlexChart (line chart) in response to a mouse click but I am having trouble. I need to know how to set the horizontal position based on the hit test. Also, the line marker does not seem to render.

    
            private void MainChart_MouseDown(object sender, MouseButtonEventArgs e)
            {
                var hitInfo = mainChart.HitTest(e.GetPosition(mainChart));
    
                var time = hitInfo.X; // DateTime
                mainChart.Layers.Add(new C1LineMarker()
                {
                    Lines = LineMarkerLines.Vertical,
                    Interaction = LineMarkerInteraction.Drag,
                    Alignment = LineMarkerAlignment.Auto,
                    DragLines = true,
                });
            }
    
    
  • Posted 19 September 2017, 7:23 pm EST

    Hi,

    There seems to be some issue when the LineMarker’s position are being specified explicitly. We are discussing this with our development team and would inform you as soon as there’s an update on this.

    (Internal Tracking Id: 286883)

    Regards,

    Ankit

  • Posted 8 November 2017, 3:43 am EST

    Any update on this?

  • Posted 14 November 2017, 10:18 am EST

    Any updates? Would be very useful to set a line marker position on mouse click…

  • Posted 4 February 2018, 10:24 pm EST

    Hi,

    The LineMarker’s position needs to specified relatively w.r.t to the chart’s PlotArea. The accepted values hence being in the range [0,1]. For example, set these two properties to 0.5 to position the LineMarker to the center of chart.

    In case you are using a Mouse event following might be helpful for you:

    var pt = e.GetPosition(flexChart);
    var lineMarker = new C1LineMarker();
    lineMarker.HorizontalPosition = (pt.X - flexChart.PlotRect.X) / flexChart.PlotRect.Width;
    lineMarker.VerticalPosition = (pt.Y - flexChart.PlotRect.Y) / flexChart.PlotRect.Height;
    

    Kindly note that setting the positions explicitly would fix the marker onto the chart. This is an intended behavior. Also, using multiple LineMarkers instances on the same chart is not suggested. We’d recommend to take a look at chart annotations instead.

    https://www.grapecity.com/en/blogs/how-to-add-interactions-to-annotations-in-net-chart

    Regards,

    Ankit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels