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

CustomLine does not work

6 Answers 135 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Georgi
Top achievements
Rank 1
Georgi asked on 08 Sep 2010, 07:25 AM
I'm trying to add CustomLine to my chart with these lines of code:

 

CustomLine line = new CustomLine();
line.StartX = 2;
line.StartY = 2;
line.EndX = 5;
line.EndY = 30; // !?!?
...

The result is strange (look at the attached picture, the end of the line is [5,5]). Because there is little help and no examples at all, would somebody help me with this "tough" example?

I've tried everything in my mind (playing with Slope, YAxisName, ElementX1, etc.). Whatever I do I couldn't add a line that is rendered as I expect giving its properties

6 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 13 Sep 2010, 11:49 AM
Hello Georgi,

The StartX, EndX, etc properties do not represent coordinate points, they merely show where the line is clipped.The function which draws the custom line is : y = mx + b, where 'm' is the Slope and 'b' is YIntercept. The Slope is defined as : (y2 - y1)/(x2 - x1).

In your case, in order to draw a line from Point (2, 2) to Point(5, 30), you would need to define it in the following way:
RadChart1.DefaultView.ChartArea.Annotations.Add(new CustomLine() { StartX = 2, EndX = 5, YIntercept = -16.66, Slope = 9.33});

Hope this helps. A help topic on the matter will be added in the nearest future.

Best wishes,
Nikolay
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Georgi
Top achievements
Rank 1
answered on 16 Sep 2010, 03:25 PM
Knowing the actual function that represents the line and some base trigonometry from high school it takes a few lines of code to draw almost every possible line with starting and ending coordinates as input. So thanks for the hint :)

But I said almost every possible line... what about a vertical line? My basic math knowledge tells me that it's not possible with your approach, is it? :) And is there any other way to draw a line from (2, 2) to (2,4)?

I'm not such a stickler, I just try to find some solution for my other problems with MarkedZones (look here). If I can find a way to draw vertical lines, then I can just draw 4 lines to form a rectangle, don't I?
0
Nikolay
Telerik team
answered on 21 Sep 2010, 07:21 AM
Hello Georgi,

You can draw a vertical line from Point( 2, 2 ) to Point( 2, 4 ) by setting PositiveInfinity for the Slope. Here is a sample code snippet :
RadChart1.DefaultView.ChartArea.Annotations.Add(new CustomLine() { StartY = 2, EndY = 4, XIntercept = 2, Slope = double.PositiveInfinity });

Hope this helps.

Sincerely yours,
Nikolay
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Brian
Top achievements
Rank 1
answered on 04 Aug 2011, 03:19 PM
I am trying to create a horizontal custom line.  Using your instructions above, that would be:

new
CustomLine { YIntercept = 5, Slope = double.PositiveInfinity, MinX = 5, MaxX = 15 };

for a line with a Y value of 5 that extends from X=5 to X=15, right?  It doesn't seem to work.  I can't get it to actually draw the line. 
0
Sia
Telerik team
answered on 04 Aug 2011, 04:19 PM
Hello Brian,

Please find our answer in the other forum thread concerning the same issue.

Greetings,
Sia
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Manesh
Top achievements
Rank 2
answered on 01 Feb 2012, 11:20 AM
HELLO GEORGI,


 This is manesh its nice to see custom line working in your programming but i'm unable to have custome line syntax error is comming so please tell me how to write it or please mail your code to manesh561@gmail.com
Tags
Chart
Asked by
Georgi
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Georgi
Top achievements
Rank 1
Brian
Top achievements
Rank 1
Sia
Telerik team
Manesh
Top achievements
Rank 2
Share this question
or