This is a migrated thread and some comments may be shown as answers.

How to select a series

1 Answer 101 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
OPTCOM
Top achievements
Rank 1
OPTCOM asked on 30 May 2014, 05:21 AM
Hello everyone ,

I am trying to select a line series (NOT A POINT) using the mouse .In fact I want to create two cursor to show the distance of two points by using two line series .  These  cursors should be dragged and moved by the mouse , something like select the line first , and the drag it to other position. I don't know how to select the line. 
I have found something like that but it's for Rad Chart not for ChartView.
http://blogs.telerik.com/automated-testing-tools/posts/09-10-01/draggable-series-items-in-radchart-for-winforms

Can some one tell me how to do that ?

Thanks a  lot.


1 Answer, 1 is accepted

Sort by
0
George
Telerik team
answered on 02 Jun 2014, 01:35 PM
Hello Noah,

Thank you for writing.

You can however create a custom renderer and custom draw parts by following the article Custom rendering. In your custom renderer you will need to expose the DrawParts property as it is currently protected, in order to be able to access the custom draw part. Your custom draw part must inherit from LineSeriesDrawPart, for the sake of this example. In it you can implement the following method, which will return the clicked series:
public ChartSeries HitTestSeries(Point location)
{
    List<PointF[]> allPoints = GetPointsPositionsArrays();
    foreach (PointF[] points in allPoints)
    {
        GraphicsPath path = GetLinePaths(points);
        if (path == null)
        {
            continue;
        }
 
        if (path.IsVisible(location))
        {
            return this.Element;
        }
    }
 
    return null;
}

And here is how you can use it:
void chart_MouseClick(object sender, MouseEventArgs e)
{
    var renderer = yourCustomRenderer;
 
    var drawParts = renderer.DrawParts;
     
    foreach (var part in drawParts)
    {
        if (part is YourCustomDrawPart)
        {
            var hitSeries = ((YourCustomDrawPart)part).HitTestSeries(e.Location);
        }
    }
}

I hope this information will be of help.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
ChartView
Asked by
OPTCOM
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or