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

moving custom grid line based on mouse move event

3 Answers 73 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Venkatesh
Top achievements
Rank 1
Venkatesh asked on 06 Jan 2012, 07:44 AM
I am using telerik chart for silverlight. I created a custom grid line which should move as we move the mouse. Hence, I calculate the x intercept based on the x coordinate of the mouse. when I do it, there is always a gap between the cursor and the line. how do we solve this issue.
thanks
venkatesh

3 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 09 Jan 2012, 04:34 PM
Hi Venkatesh,

You may use the approach shown in this help topic to achieve your scenario.

All the best,
Evgenia
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Venkatesh
Top achievements
Rank 1
answered on 09 Jan 2012, 08:55 PM
I did use that link to create a custom grid line using the following code.

 

 

 

 

 CustomGridline gridline = new CustomGridLine();

gridline.XIntercept = collection[0].Date.ToOADate();

gridline.Stroke =

 

new SolidColorBrush(Colors.Green);

gridline.StrokeThickness = .3;

tChart.DefaultView.ChartArea.Annotations.Add(gridline);

Then I move the grid line using the following code. I am not sure how to convert the position X to a date value. I cannot use TOaDate() as it gives some wrong date. if I use position.x -67 then I get somewhat close coordinates for the cursor but not exact. How do you solve this.


 

void ChartArea_MouseMove(object sender, MouseEventArgs e)

{

 

ChartArea plotAreaPanel = sender as ChartArea;

 

var position = e.GetPosition(plotAreaPanel);

 

double posX = double.Parse(position.X.ToString());

 

var x = plotAreaPanel.AxisX.ConvertPhysicalUnitsToData(posX -67);

 

AnnotationCollection cGridCollection1 = chart.DefaultView.ChartArea.Annotations;

 

    if (cGridCollection1.Count == 1)

     {

         (cGridCollection1[0]

 

        as CustomGridLine).XIntercept = x;

      }

}

 

0
Venkatesh
Top achievements
Rank 1
answered on 09 Jan 2012, 09:29 PM
I fixed this issue. I used chart area instead of plot area. That was the issue
Tags
Chart
Asked by
Venkatesh
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Venkatesh
Top achievements
Rank 1
Share this question
or